Tim13ekd commited on
Commit
2a9840f
·
verified ·
1 Parent(s): f4beeaf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -7
app.py CHANGED
@@ -1,21 +1,27 @@
 
 
 
 
 
 
 
 
1
  def execute_ffmpeg_image_to_video(image_file):
2
- """Erzeugt ein 5-Sekunden-Video aus einem Bild im HF Space"""
3
  if image_file is None:
4
  return None, "❌ Keine Datei ausgewählt"
5
 
6
- temp_dir = tempfile.mkdtemp()
7
- file_path = Path(image_file.name)
8
- dest_path = Path(temp_dir) / file_path.name.replace(" ", "_")
9
- shutil.copy(file_path, dest_path)
10
 
 
11
  output_file = Path(temp_dir) / f"output_{uuid.uuid4().hex}.mp4"
12
 
13
- # Minimalistischer, zuverlässiger FFmpeg-Befehl
14
  cmd = [
15
  "ffmpeg",
16
  "-y",
17
  "-loop", "1",
18
- "-i", str(dest_path),
19
  "-vf", "fps=25,format=yuv420p",
20
  "-t", "5",
21
  str(output_file)
@@ -27,3 +33,14 @@ def execute_ffmpeg_image_to_video(image_file):
27
  return None, f"❌ FFmpeg Fehler:\n{e.stderr}"
28
 
29
  return str(output_file), "✅ Video erfolgreich erstellt"
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import subprocess
3
+ import tempfile
4
+ import uuid
5
+ from pathlib import Path
6
+
7
+ allowed_medias = [".png", ".jpg", ".jpeg", ".bmp", ".gif", ".tiff"]
8
+
9
  def execute_ffmpeg_image_to_video(image_file):
10
+ """Erzeugt ein 5-Sekunden-Video aus einem Bild in HF Space"""
11
  if image_file is None:
12
  return None, "❌ Keine Datei ausgewählt"
13
 
14
+ # Gradio liefert manchmal ein Dict, manchmal ein File-Objekt
15
+ image_path = Path(image_file.name) if hasattr(image_file, "name") else Path(image_file)
 
 
16
 
17
+ temp_dir = tempfile.mkdtemp()
18
  output_file = Path(temp_dir) / f"output_{uuid.uuid4().hex}.mp4"
19
 
 
20
  cmd = [
21
  "ffmpeg",
22
  "-y",
23
  "-loop", "1",
24
+ "-i", str(image_path),
25
  "-vf", "fps=25,format=yuv420p",
26
  "-t", "5",
27
  str(output_file)
 
33
  return None, f"❌ FFmpeg Fehler:\n{e.stderr}"
34
 
35
  return str(output_file), "✅ Video erfolgreich erstellt"
36
+
37
+ # Gradio UI
38
+ with gr.Blocks() as demo:
39
+ gr.Markdown("# Bild → Video Konverter")
40
+ img_input = gr.File(file_types=allowed_medias, label="Bild auswählen")
41
+ out_video = gr.Video(interactive=False, label="Generiertes Video")
42
+ status = gr.Textbox(interactive=False, label="Status")
43
+ btn = gr.Button("Video erstellen")
44
+ btn.click(fn=execute_ffmpeg_image_to_video, inputs=[img_input], outputs=[out_video, status])
45
+
46
+ demo.launch()