Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,7 +34,7 @@ def save_temp_audio(audio_file):
|
|
| 34 |
else:
|
| 35 |
raise ValueError("Das übergebene Audio ist kein gültiges Dateiformat oder NamedString.")
|
| 36 |
|
| 37 |
-
def generate_slideshow_with_audio(images, input_text, duration_per_word=0.5, y_pos=0.5, fade_duration=0.7, font_size=60, audio_file=None):
|
| 38 |
if not images:
|
| 39 |
return None, "❌ Keine Bilder ausgewählt"
|
| 40 |
|
|
@@ -51,9 +51,13 @@ def generate_slideshow_with_audio(images, input_text, duration_per_word=0.5, y_p
|
|
| 51 |
if audio_file:
|
| 52 |
temp_audio_file = save_temp_audio(audio_file)
|
| 53 |
|
| 54 |
-
#
|
| 55 |
-
for i,
|
|
|
|
| 56 |
clip_path = Path(temp_dir) / f"clip_{i}.mp4"
|
|
|
|
|
|
|
|
|
|
| 57 |
text = word
|
| 58 |
|
| 59 |
vf_filters = (
|
|
@@ -75,16 +79,16 @@ def generate_slideshow_with_audio(images, input_text, duration_per_word=0.5, y_p
|
|
| 75 |
cmd = [
|
| 76 |
"ffmpeg",
|
| 77 |
"-y",
|
| 78 |
-
"-
|
| 79 |
-
"-
|
| 80 |
-
"-
|
| 81 |
"-vf", vf_filters,
|
| 82 |
str(clip_path)
|
| 83 |
]
|
| 84 |
try:
|
| 85 |
subprocess.run(cmd, check=True, capture_output=True, text=True)
|
| 86 |
except subprocess.CalledProcessError as e:
|
| 87 |
-
return None, f"❌ FFmpeg Fehler bei
|
| 88 |
|
| 89 |
clips.append(clip_path)
|
| 90 |
|
|
@@ -141,7 +145,8 @@ with gr.Blocks() as demo:
|
|
| 141 |
placeholder="Gib hier den Text ein, der Wort für Wort eingeblendet werden soll",
|
| 142 |
lines=5
|
| 143 |
)
|
| 144 |
-
|
|
|
|
| 145 |
fade_input = gr.Number(value=0.7, label="Fade Dauer in Sekunden", precision=1)
|
| 146 |
ypos_input = gr.Slider(minimum=0.0, maximum=0.9, step=0.01, value=0.5, label="Y-Position für alle Texte (0=oben, 0.5=mitte, 0.9=unten)")
|
| 147 |
font_size_input = gr.Number(value=60, label="Textgröße (px)")
|
|
@@ -157,8 +162,8 @@ with gr.Blocks() as demo:
|
|
| 157 |
btn = gr.Button("Video erstellen")
|
| 158 |
btn.click(
|
| 159 |
fn=generate_slideshow_with_audio,
|
| 160 |
-
inputs=[img_input, text_input,
|
| 161 |
outputs=[out_video, status]
|
| 162 |
)
|
| 163 |
|
| 164 |
-
demo.launch()
|
|
|
|
| 34 |
else:
|
| 35 |
raise ValueError("Das übergebene Audio ist kein gültiges Dateiformat oder NamedString.")
|
| 36 |
|
| 37 |
+
def generate_slideshow_with_audio(images, input_text, duration_per_word=0.5, duration_per_image=3, y_pos=0.5, fade_duration=0.7, font_size=60, audio_file=None):
|
| 38 |
if not images:
|
| 39 |
return None, "❌ Keine Bilder ausgewählt"
|
| 40 |
|
|
|
|
| 51 |
if audio_file:
|
| 52 |
temp_audio_file = save_temp_audio(audio_file)
|
| 53 |
|
| 54 |
+
# Clips für jedes Bild erstellen
|
| 55 |
+
for i, img_path in enumerate(images):
|
| 56 |
+
img_path = Path(img_path.name) # Sicherstellen, dass es den richtigen Pfad hat
|
| 57 |
clip_path = Path(temp_dir) / f"clip_{i}.mp4"
|
| 58 |
+
|
| 59 |
+
# Berechnen der Dauer für das aktuelle Wort
|
| 60 |
+
word = words[i % total_words] # Wenn weniger Wörter als Bilder, wiederholen wir den Text
|
| 61 |
text = word
|
| 62 |
|
| 63 |
vf_filters = (
|
|
|
|
| 79 |
cmd = [
|
| 80 |
"ffmpeg",
|
| 81 |
"-y",
|
| 82 |
+
"-loop", "1",
|
| 83 |
+
"-i", str(img_path),
|
| 84 |
+
"-t", str(duration_per_image),
|
| 85 |
"-vf", vf_filters,
|
| 86 |
str(clip_path)
|
| 87 |
]
|
| 88 |
try:
|
| 89 |
subprocess.run(cmd, check=True, capture_output=True, text=True)
|
| 90 |
except subprocess.CalledProcessError as e:
|
| 91 |
+
return None, f"❌ FFmpeg Fehler bei Bild {i+1}:\n{e.stderr}"
|
| 92 |
|
| 93 |
clips.append(clip_path)
|
| 94 |
|
|
|
|
| 145 |
placeholder="Gib hier den Text ein, der Wort für Wort eingeblendet werden soll",
|
| 146 |
lines=5
|
| 147 |
)
|
| 148 |
+
duration_word_input = gr.Number(value=0.5, label="Dauer pro Wort in Sekunden", precision=1)
|
| 149 |
+
duration_image_input = gr.Number(value=3, label="Dauer pro Bild in Sekunden", precision=1)
|
| 150 |
fade_input = gr.Number(value=0.7, label="Fade Dauer in Sekunden", precision=1)
|
| 151 |
ypos_input = gr.Slider(minimum=0.0, maximum=0.9, step=0.01, value=0.5, label="Y-Position für alle Texte (0=oben, 0.5=mitte, 0.9=unten)")
|
| 152 |
font_size_input = gr.Number(value=60, label="Textgröße (px)")
|
|
|
|
| 162 |
btn = gr.Button("Video erstellen")
|
| 163 |
btn.click(
|
| 164 |
fn=generate_slideshow_with_audio,
|
| 165 |
+
inputs=[img_input, text_input, duration_word_input, duration_image_input, ypos_input, fade_input, font_size_input, audio_input],
|
| 166 |
outputs=[out_video, status]
|
| 167 |
)
|
| 168 |
|
| 169 |
+
demo.launch()
|