Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,28 +7,20 @@ import uuid
|
|
| 7 |
allowed_medias = [".png", ".jpg", ".jpeg", ".bmp", ".gif", ".tiff"]
|
| 8 |
|
| 9 |
def generate_slideshow(images, duration):
|
| 10 |
-
"""
|
| 11 |
-
Erzeugt ein Video aus mehreren Bildern in einer frei wählbaren Reihenfolge.
|
| 12 |
-
Dauer: Sekunden pro Bild
|
| 13 |
-
"""
|
| 14 |
if not images:
|
| 15 |
return None, "❌ Keine Bilder ausgewählt"
|
| 16 |
|
| 17 |
-
# Temporäres Verzeichnis
|
| 18 |
temp_dir = tempfile.mkdtemp()
|
| 19 |
filelist_path = Path(temp_dir) / "filelist.txt"
|
| 20 |
output_file = Path(temp_dir) / f"slideshow_{uuid.uuid4().hex}.mp4"
|
| 21 |
|
| 22 |
-
# FFmpeg
|
| 23 |
-
# file 'path/to/image'
|
| 24 |
-
# duration 5
|
| 25 |
with open(filelist_path, "w") as f:
|
| 26 |
for img in images:
|
| 27 |
img_path = Path(img.name) if hasattr(img, "name") else Path(img)
|
| 28 |
-
# Breite/Höhe auf gerade Werte skalieren
|
| 29 |
f.write(f"file '{img_path}'\n")
|
| 30 |
f.write(f"duration {duration}\n")
|
| 31 |
-
# FFmpeg benötigt letztes Bild nochmal, um das Ende korrekt zu machen
|
| 32 |
f.write(f"file '{Path(images[-1].name if hasattr(images[-1], 'name') else images[-1])}'\n")
|
| 33 |
|
| 34 |
cmd = [
|
|
@@ -55,7 +47,12 @@ def generate_slideshow(images, duration):
|
|
| 55 |
with gr.Blocks() as demo:
|
| 56 |
gr.Markdown("# Slideshow Video Generator")
|
| 57 |
|
| 58 |
-
img_input = gr.File(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
duration_input = gr.Number(value=3, label="Dauer pro Bild in Sekunden", precision=1)
|
| 60 |
out_video = gr.Video(interactive=False, label="Generiertes Video")
|
| 61 |
status = gr.Textbox(interactive=False, label="Status")
|
|
|
|
| 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 |
|
|
|
|
| 14 |
temp_dir = tempfile.mkdtemp()
|
| 15 |
filelist_path = Path(temp_dir) / "filelist.txt"
|
| 16 |
output_file = Path(temp_dir) / f"slideshow_{uuid.uuid4().hex}.mp4"
|
| 17 |
|
| 18 |
+
# FFmpeg Filelist erstellen
|
|
|
|
|
|
|
| 19 |
with open(filelist_path, "w") as f:
|
| 20 |
for img in images:
|
| 21 |
img_path = Path(img.name) if hasattr(img, "name") else Path(img)
|
|
|
|
| 22 |
f.write(f"file '{img_path}'\n")
|
| 23 |
f.write(f"duration {duration}\n")
|
|
|
|
| 24 |
f.write(f"file '{Path(images[-1].name if hasattr(images[-1], 'name') else images[-1])}'\n")
|
| 25 |
|
| 26 |
cmd = [
|
|
|
|
| 47 |
with gr.Blocks() as demo:
|
| 48 |
gr.Markdown("# Slideshow Video Generator")
|
| 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")
|