Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,6 @@ import uuid
|
|
| 7 |
allowed_medias = [".png", ".jpg", ".jpeg", ".bmp", ".gif", ".tiff"]
|
| 8 |
|
| 9 |
def generate_slideshow(images, duration):
|
| 10 |
-
"""Erzeugt ein Video aus mehreren Bildern in einer frei wählbaren Reihenfolge."""
|
| 11 |
if not images:
|
| 12 |
return None, "❌ Keine Bilder ausgewählt"
|
| 13 |
|
|
@@ -15,13 +14,12 @@ def generate_slideshow(images, duration):
|
|
| 15 |
filelist_path = Path(temp_dir) / "filelist.txt"
|
| 16 |
output_file = Path(temp_dir) / f"slideshow_{uuid.uuid4().hex}.mp4"
|
| 17 |
|
| 18 |
-
# FFmpeg Filelist
|
| 19 |
with open(filelist_path, "w") as f:
|
| 20 |
for img in images:
|
| 21 |
-
|
| 22 |
-
f.write(f"file '{img_path}'\n")
|
| 23 |
f.write(f"duration {duration}\n")
|
| 24 |
-
f.write(f"file '{
|
| 25 |
|
| 26 |
cmd = [
|
| 27 |
"ffmpeg",
|
|
@@ -33,35 +31,20 @@ def generate_slideshow(images, duration):
|
|
| 33 |
str(output_file)
|
| 34 |
]
|
| 35 |
|
| 36 |
-
|
| 37 |
-
subprocess.run(cmd, check=True, text=True, capture_output=True)
|
| 38 |
-
except subprocess.CalledProcessError as e:
|
| 39 |
-
return None, f"❌ FFmpeg Fehler:\n{e.stderr}"
|
| 40 |
|
| 41 |
if output_file.exists():
|
| 42 |
return str(output_file), f"✅ Slideshow Video erstellt ({len(images)} Bilder, {duration}s pro Bild)"
|
| 43 |
else:
|
| 44 |
return None, "❌ Video konnte nicht erstellt werden"
|
| 45 |
|
| 46 |
-
# Gradio UI
|
| 47 |
with gr.Blocks() as demo:
|
| 48 |
-
gr.
|
| 49 |
-
|
| 50 |
-
img_input = gr.File(
|
| 51 |
-
label="Bilder auswählen (mehrere)",
|
| 52 |
-
file_types=allowed_medias,
|
| 53 |
-
type="file",
|
| 54 |
-
file_types_multiple=True # <--- erlaubt mehrere Dateien
|
| 55 |
-
)
|
| 56 |
duration_input = gr.Number(value=3, label="Dauer pro Bild in Sekunden", precision=1)
|
| 57 |
out_video = gr.Video(interactive=False, label="Generiertes Video")
|
| 58 |
status = gr.Textbox(interactive=False, label="Status")
|
| 59 |
|
| 60 |
btn = gr.Button("Video erstellen")
|
| 61 |
-
btn.click(
|
| 62 |
-
fn=generate_slideshow,
|
| 63 |
-
inputs=[img_input, duration_input],
|
| 64 |
-
outputs=[out_video, status]
|
| 65 |
-
)
|
| 66 |
|
| 67 |
demo.launch()
|
|
|
|
| 7 |
allowed_medias = [".png", ".jpg", ".jpeg", ".bmp", ".gif", ".tiff"]
|
| 8 |
|
| 9 |
def generate_slideshow(images, duration):
|
|
|
|
| 10 |
if not images:
|
| 11 |
return None, "❌ Keine Bilder ausgewählt"
|
| 12 |
|
|
|
|
| 14 |
filelist_path = Path(temp_dir) / "filelist.txt"
|
| 15 |
output_file = Path(temp_dir) / f"slideshow_{uuid.uuid4().hex}.mp4"
|
| 16 |
|
| 17 |
+
# FFmpeg Filelist
|
| 18 |
with open(filelist_path, "w") as f:
|
| 19 |
for img in images:
|
| 20 |
+
f.write(f"file '{img.name}'\n")
|
|
|
|
| 21 |
f.write(f"duration {duration}\n")
|
| 22 |
+
f.write(f"file '{images[-1].name}'\n")
|
| 23 |
|
| 24 |
cmd = [
|
| 25 |
"ffmpeg",
|
|
|
|
| 31 |
str(output_file)
|
| 32 |
]
|
| 33 |
|
| 34 |
+
subprocess.run(cmd, check=True)
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
if output_file.exists():
|
| 37 |
return str(output_file), f"✅ Slideshow Video erstellt ({len(images)} Bilder, {duration}s pro Bild)"
|
| 38 |
else:
|
| 39 |
return None, "❌ Video konnte nicht erstellt werden"
|
| 40 |
|
|
|
|
| 41 |
with gr.Blocks() as demo:
|
| 42 |
+
img_input = gr.File(label="Bilder auswählen (mehrere)", type="file", file_types=None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
duration_input = gr.Number(value=3, label="Dauer pro Bild in Sekunden", precision=1)
|
| 44 |
out_video = gr.Video(interactive=False, label="Generiertes Video")
|
| 45 |
status = gr.Textbox(interactive=False, label="Status")
|
| 46 |
|
| 47 |
btn = gr.Button("Video erstellen")
|
| 48 |
+
btn.click(fn=generate_slideshow, inputs=[img_input, duration_input], outputs=[out_video, status])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
demo.launch()
|