Tim13ekd commited on
Commit
91572a7
·
verified ·
1 Parent(s): 86abf34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -3,17 +3,19 @@ import subprocess
3
  import uuid
4
  import os
5
 
6
- # -------- Video Trim Funktion --------
7
  def trim_video(file, start, duration):
8
  try:
9
  input_path = f"/tmp/{uuid.uuid4()}_in.mp4"
10
  output_path = f"/tmp/{uuid.uuid4()}_out.mp4"
11
 
12
- # --- Datei korrekt lesen ---
13
- if hasattr(file, "read"): # SpooledTemporaryFile oder Dateiobjekt
14
- file_bytes = file.read()
15
- else: # NamedString oder direkt Pfad
16
- file_bytes = file
 
 
 
17
 
18
  # --- Datei speichern ---
19
  with open(input_path, "wb") as f:
@@ -33,7 +35,6 @@ def trim_video(file, start, duration):
33
  ]
34
  subprocess.run(cmd, check=True, capture_output=True)
35
 
36
- # --- Prüfen, ob Output existiert ---
37
  if not os.path.exists(output_path):
38
  return "Fehler: Output-Video wurde nicht erstellt."
39
 
@@ -45,7 +46,6 @@ def trim_video(file, start, duration):
45
  except Exception as e:
46
  return f"Allgemeiner Fehler:\n{str(e)}"
47
 
48
-
49
  # -------- Gradio Interface --------
50
  iface = gr.Interface(
51
  fn=trim_video,
@@ -59,5 +59,4 @@ iface = gr.Interface(
59
  description="Trimme Videos direkt im Hugging Face Space. Fehlermeldungen werden angezeigt, falls etwas schiefgeht."
60
  )
61
 
62
- # -------- Server starten --------
63
  iface.launch(server_name="0.0.0.0", server_port=7860)
 
3
  import uuid
4
  import os
5
 
 
6
  def trim_video(file, start, duration):
7
  try:
8
  input_path = f"/tmp/{uuid.uuid4()}_in.mp4"
9
  output_path = f"/tmp/{uuid.uuid4()}_out.mp4"
10
 
11
+ # --- Datei in Bytes konvertieren ---
12
+ if hasattr(file, "read"):
13
+ file_bytes = file.read() # File-Objekt
14
+ elif isinstance(file, str):
15
+ # NamedString liefert String → in Bytes umwandeln
16
+ file_bytes = file.encode("utf-8")
17
+ else:
18
+ return f"Unbekannter Dateityp: {type(file)}"
19
 
20
  # --- Datei speichern ---
21
  with open(input_path, "wb") as f:
 
35
  ]
36
  subprocess.run(cmd, check=True, capture_output=True)
37
 
 
38
  if not os.path.exists(output_path):
39
  return "Fehler: Output-Video wurde nicht erstellt."
40
 
 
46
  except Exception as e:
47
  return f"Allgemeiner Fehler:\n{str(e)}"
48
 
 
49
  # -------- Gradio Interface --------
50
  iface = gr.Interface(
51
  fn=trim_video,
 
59
  description="Trimme Videos direkt im Hugging Face Space. Fehlermeldungen werden angezeigt, falls etwas schiefgeht."
60
  )
61
 
 
62
  iface.launch(server_name="0.0.0.0", server_port=7860)