Tim13ekd commited on
Commit
029e266
·
verified ·
1 Parent(s): 2ab5e5e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -6,10 +6,11 @@ import subprocess
6
 
7
  allowed_medias = [".png", ".jpg", ".jpeg", ".bmp", ".gif", ".tiff"]
8
 
9
- def generate_slideshow_with_smooth_text(images, duration, texts=None, fade_duration=0.7):
10
  """
11
- Smooth Text Fade-In/Fade-Out für jedes Bild (wie faceless videos)
12
- fade_duration: Dauer des Ein-/Ausblendens in Sekunden
 
13
  """
14
  if not images:
15
  return None, "❌ Keine Bilder ausgewählt"
@@ -17,19 +18,23 @@ def generate_slideshow_with_smooth_text(images, duration, texts=None, fade_durat
17
  temp_dir = tempfile.mkdtemp()
18
  clips = []
19
 
 
20
  if texts is None:
21
  texts = [""] * len(images)
 
 
22
 
23
  for i, img_path in enumerate(images):
24
  clip_path = Path(temp_dir) / f"clip_{i}.mp4"
25
  text = texts[i] if i < len(texts) else ""
 
26
 
27
  drawtext = ""
28
  if text:
29
- # Smooth Fade-In / Fade-Out
30
  drawtext = (
31
  f"drawtext=text='{text}':fontcolor=white:fontsize=40:borderw=2:"
32
- f"x=(w-text_w)/2:y=(h-text_h)/2:"
33
  f"alpha='if(lt(t,{fade_duration}), t/{fade_duration}, if(lt(t,{duration}-{fade_duration}), 1, ({duration}-t)/{fade_duration}))'"
34
  )
35
 
@@ -67,29 +72,31 @@ def generate_slideshow_with_smooth_text(images, duration, texts=None, fade_durat
67
  subprocess.run(cmd_concat, check=True)
68
 
69
  if output_file.exists():
70
- return str(output_file), f"✅ Slideshow mit smooth Text Fade erstellt ({len(images)} Bilder)"
71
  else:
72
  return None, "❌ Video konnte nicht erstellt werden"
73
 
74
  # Gradio UI
75
  with gr.Blocks() as demo:
76
- gr.Markdown("# Slideshow mit smooth Fade-In/Fade-Out Text")
77
 
78
  img_input = gr.Files(label="Bilder auswählen (mehrere)", file_types=allowed_medias)
79
  duration_input = gr.Number(value=3, label="Dauer pro Bild in Sekunden", precision=1)
80
  fade_input = gr.Number(value=0.7, label="Fade Dauer in Sekunden", precision=1)
81
  text_input = gr.Textbox(label="Texte pro Bild (mit Komma trennen)", placeholder="Text1, Text2, Text3 ...")
 
82
  out_video = gr.Video(interactive=False, label="Generiertes Video")
83
  status = gr.Textbox(interactive=False, label="Status")
84
 
85
- def wrapper(images, duration, fade_duration, text_str):
86
  texts = [t.strip() for t in text_str.split(",")] if text_str else None
87
- return generate_slideshow_with_smooth_text(images, duration, texts, fade_duration)
 
88
 
89
  btn = gr.Button("Video erstellen")
90
  btn.click(
91
  fn=wrapper,
92
- inputs=[img_input, duration_input, fade_input, text_input],
93
  outputs=[out_video, status]
94
  )
95
 
 
6
 
7
  allowed_medias = [".png", ".jpg", ".jpeg", ".bmp", ".gif", ".tiff"]
8
 
9
+ def generate_slideshow_with_text_ypos(images, duration, texts=None, y_positions=None, fade_duration=0.7):
10
  """
11
+ Slideshow mit smooth Fade-In/Fade-Out Text, Y-Position pro Bild einstellbar.
12
+ texts: Liste der Strings pro Bild
13
+ y_positions: Liste der Y-Positionen pro Bild (0=oben, 0.5=mitte, 1=unten)
14
  """
15
  if not images:
16
  return None, "❌ Keine Bilder ausgewählt"
 
18
  temp_dir = tempfile.mkdtemp()
19
  clips = []
20
 
21
+ # Standardwerte
22
  if texts is None:
23
  texts = [""] * len(images)
24
+ if y_positions is None:
25
+ y_positions = [0.5] * len(images)
26
 
27
  for i, img_path in enumerate(images):
28
  clip_path = Path(temp_dir) / f"clip_{i}.mp4"
29
  text = texts[i] if i < len(texts) else ""
30
+ y_pos = y_positions[i] if i < len(y_positions) else 0.5
31
 
32
  drawtext = ""
33
  if text:
34
+ # Smooth Fade-In / Fade-Out, Y-Position dynamisch
35
  drawtext = (
36
  f"drawtext=text='{text}':fontcolor=white:fontsize=40:borderw=2:"
37
+ f"x=(w-text_w)/2:y=(h-text_h)*{y_pos}:"
38
  f"alpha='if(lt(t,{fade_duration}), t/{fade_duration}, if(lt(t,{duration}-{fade_duration}), 1, ({duration}-t)/{fade_duration}))'"
39
  )
40
 
 
72
  subprocess.run(cmd_concat, check=True)
73
 
74
  if output_file.exists():
75
+ return str(output_file), f"✅ Slideshow erstellt ({len(images)} Bilder mit Text + Y-Position)"
76
  else:
77
  return None, "❌ Video konnte nicht erstellt werden"
78
 
79
  # Gradio UI
80
  with gr.Blocks() as demo:
81
+ gr.Markdown("# Slideshow mit Text und Y-Position")
82
 
83
  img_input = gr.Files(label="Bilder auswählen (mehrere)", file_types=allowed_medias)
84
  duration_input = gr.Number(value=3, label="Dauer pro Bild in Sekunden", precision=1)
85
  fade_input = gr.Number(value=0.7, label="Fade Dauer in Sekunden", precision=1)
86
  text_input = gr.Textbox(label="Texte pro Bild (mit Komma trennen)", placeholder="Text1, Text2, Text3 ...")
87
+ ypos_input = gr.Textbox(label="Y-Position pro Bild (0=oben,0.5=mitte,1=unten, mit Komma trennen)", placeholder="0.2,0.5,0.8")
88
  out_video = gr.Video(interactive=False, label="Generiertes Video")
89
  status = gr.Textbox(interactive=False, label="Status")
90
 
91
+ def wrapper(images, duration, fade_duration, text_str, ypos_str):
92
  texts = [t.strip() for t in text_str.split(",")] if text_str else None
93
+ y_positions = [float(y.strip()) for y in ypos_str.split(",")] if ypos_str else None
94
+ return generate_slideshow_with_text_ypos(images, duration, texts, y_positions, fade_duration)
95
 
96
  btn = gr.Button("Video erstellen")
97
  btn.click(
98
  fn=wrapper,
99
+ inputs=[img_input, duration_input, fade_input, text_input, ypos_input],
100
  outputs=[out_video, status]
101
  )
102