Tim13ekd commited on
Commit
e5b621e
·
verified ·
1 Parent(s): 7128f30

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -4
app.py CHANGED
@@ -1,11 +1,20 @@
 
 
 
 
 
 
 
 
 
1
  def execute_ffmpeg_image_to_video(image_file):
2
- """Erzeugt ein 5-Sekunden-Video aus einem Bild, selbst bei ungeraden Dimensionen"""
3
  if image_file is None:
4
  return None, "❌ Keine Datei ausgewählt"
5
 
 
6
  image_path = Path(image_file.name) if hasattr(image_file, "name") else Path(image_file)
7
 
8
- import tempfile, uuid
9
  temp_dir = tempfile.mkdtemp()
10
  output_file = Path(temp_dir) / f"output_{uuid.uuid4().hex}.mp4"
11
 
@@ -19,10 +28,24 @@ def execute_ffmpeg_image_to_video(image_file):
19
  str(output_file)
20
  ]
21
 
22
- import subprocess
23
  try:
24
  subprocess.run(cmd, check=True, text=True, capture_output=True)
25
  except subprocess.CalledProcessError as e:
26
  return None, f"❌ FFmpeg Fehler:\n{e.stderr}"
27
 
28
- return str(output_file), "✅ Video erfolgreich erstellt"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import subprocess
3
+ import tempfile
4
+ from pathlib import Path
5
+ import uuid
6
+ import shutil
7
+
8
+ allowed_medias = [".png", ".jpg", ".jpeg", ".bmp", ".gif", ".tiff"]
9
+
10
  def execute_ffmpeg_image_to_video(image_file):
 
11
  if image_file is None:
12
  return None, "❌ Keine Datei ausgewählt"
13
 
14
+ # Gradio liefert Upload-Pfad
15
  image_path = Path(image_file.name) if hasattr(image_file, "name") else Path(image_file)
16
 
17
+ # Erstelle temporäres Verzeichnis
18
  temp_dir = tempfile.mkdtemp()
19
  output_file = Path(temp_dir) / f"output_{uuid.uuid4().hex}.mp4"
20
 
 
28
  str(output_file)
29
  ]
30
 
 
31
  try:
32
  subprocess.run(cmd, check=True, text=True, capture_output=True)
33
  except subprocess.CalledProcessError as e:
34
  return None, f"❌ FFmpeg Fehler:\n{e.stderr}"
35
 
36
+ # Gradio benötigt einen String-Pfad oder URL
37
+ if output_file.exists():
38
+ return str(output_file), "✅ Video erfolgreich erstellt"
39
+ else:
40
+ return None, "❌ Video konnte nicht erstellt werden"
41
+
42
+ # Gradio UI
43
+ with gr.Blocks() as demo:
44
+ gr.Markdown("# Bild → Video Konverter")
45
+ img_input = gr.File(file_types=allowed_medias, label="Bild auswählen")
46
+ out_video = gr.Video(interactive=False, label="Generiertes Video")
47
+ status = gr.Textbox(interactive=False, label="Status")
48
+ btn = gr.Button("Video erstellen")
49
+ btn.click(fn=execute_ffmpeg_image_to_video, inputs=[img_input], outputs=[out_video, status])
50
+
51
+ demo.launch()