Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,11 +34,10 @@ 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, duration_per_image=3,
|
| 38 |
if not images:
|
| 39 |
return None, "❌ Keine Bilder ausgewählt"
|
| 40 |
|
| 41 |
-
y_pos = min(max(0.0, y_pos), 0.9)
|
| 42 |
temp_dir = tempfile.mkdtemp()
|
| 43 |
clips = []
|
| 44 |
|
|
@@ -55,10 +54,6 @@ def generate_slideshow_with_audio(images, input_text, duration_per_word=0.5, dur
|
|
| 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 = (
|
| 64 |
"scale=w=1280:h=720:force_original_aspect_ratio=decrease,"
|
|
@@ -66,16 +61,7 @@ def generate_slideshow_with_audio(images, input_text, duration_per_word=0.5, dur
|
|
| 66 |
"fps=25,format=yuv420p"
|
| 67 |
)
|
| 68 |
|
| 69 |
-
|
| 70 |
-
# Sichere Textverarbeitung (Escape von Sonderzeichen)
|
| 71 |
-
safe_text = shlex.quote(text)
|
| 72 |
-
drawtext_filter = (
|
| 73 |
-
f",drawtext=text={safe_text}:fontcolor=white:fontsize={font_size}:borderw=2:"
|
| 74 |
-
f"x=(w-text_w)/2:y=(h-text_h)*{y_pos}:"
|
| 75 |
-
f"alpha='if(lt(t,{fade_duration}), t/{fade_duration}, if(lt(t,{duration_per_word}-{fade_duration}), 1, ({duration_per_word}-t)/{fade_duration}))'"
|
| 76 |
-
)
|
| 77 |
-
vf_filters += drawtext_filter
|
| 78 |
-
|
| 79 |
cmd = [
|
| 80 |
"ffmpeg",
|
| 81 |
"-y",
|
|
@@ -114,6 +100,15 @@ def generate_slideshow_with_audio(images, input_text, duration_per_word=0.5, dur
|
|
| 114 |
except subprocess.CalledProcessError as e:
|
| 115 |
return None, f"❌ FFmpeg Concat Fehler:\n{e.stderr}"
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
# Audio hinzufügen, falls vorhanden
|
| 118 |
if temp_audio_file:
|
| 119 |
final_output = Path(temp_dir) / f"slideshow_audio_{uuid.uuid4().hex}.mp4"
|
|
@@ -137,7 +132,7 @@ def generate_slideshow_with_audio(images, input_text, duration_per_word=0.5, dur
|
|
| 137 |
|
| 138 |
# Gradio UI
|
| 139 |
with gr.Blocks() as demo:
|
| 140 |
-
gr.Markdown("# Slideshow mit Audio und
|
| 141 |
|
| 142 |
img_input = gr.Files(label="Bilder auswählen (mehrere)", file_types=allowed_medias)
|
| 143 |
text_input = gr.Textbox(
|
|
|
|
| 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, fade_duration=0.7, font_size=60, y_pos=0.5, audio_file=None):
|
| 38 |
if not images:
|
| 39 |
return None, "❌ Keine Bilder ausgewählt"
|
| 40 |
|
|
|
|
| 41 |
temp_dir = tempfile.mkdtemp()
|
| 42 |
clips = []
|
| 43 |
|
|
|
|
| 54 |
for i, img_path in enumerate(images):
|
| 55 |
img_path = Path(img_path.name) # Sicherstellen, dass es den richtigen Pfad hat
|
| 56 |
clip_path = Path(temp_dir) / f"clip_{i}.mp4"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
vf_filters = (
|
| 59 |
"scale=w=1280:h=720:force_original_aspect_ratio=decrease,"
|
|
|
|
| 61 |
"fps=25,format=yuv420p"
|
| 62 |
)
|
| 63 |
|
| 64 |
+
# Clips für jedes Bild erstellen (ohne Text auf Bild)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
cmd = [
|
| 66 |
"ffmpeg",
|
| 67 |
"-y",
|
|
|
|
| 100 |
except subprocess.CalledProcessError as e:
|
| 101 |
return None, f"❌ FFmpeg Concat Fehler:\n{e.stderr}"
|
| 102 |
|
| 103 |
+
# Text separat anzeigen
|
| 104 |
+
# Berechnung der Zeiten für jedes Wort
|
| 105 |
+
temp_text_file = Path(temp_dir) / "text.txt"
|
| 106 |
+
with open(temp_text_file, "w") as f:
|
| 107 |
+
for i, word in enumerate(words):
|
| 108 |
+
f.write(f"file '{str(output_file)}'\n")
|
| 109 |
+
f.write(f"duration {duration_per_word}\n")
|
| 110 |
+
f.write(f"word {word}\n")
|
| 111 |
+
|
| 112 |
# Audio hinzufügen, falls vorhanden
|
| 113 |
if temp_audio_file:
|
| 114 |
final_output = Path(temp_dir) / f"slideshow_audio_{uuid.uuid4().hex}.mp4"
|
|
|
|
| 132 |
|
| 133 |
# Gradio UI
|
| 134 |
with gr.Blocks() as demo:
|
| 135 |
+
gr.Markdown("# Slideshow mit Audio und separatem Text")
|
| 136 |
|
| 137 |
img_input = gr.Files(label="Bilder auswählen (mehrere)", file_types=allowed_medias)
|
| 138 |
text_input = gr.Textbox(
|