Tim13ekd commited on
Commit
889f1d1
·
verified ·
1 Parent(s): 27e5085

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -31
app.py CHANGED
@@ -1,39 +1,22 @@
1
- from fastapi import FastAPI, UploadFile, File
2
- from fastapi.responses import FileResponse
3
- from fastapi.openapi.docs import get_swagger_ui_html
4
  import subprocess
5
  import uuid
6
  import os
7
 
8
- app = FastAPI()
9
-
10
- # -------- Healthcheck Endpoint --------
11
- @app.get("/")
12
- def health():
13
- return {"status": "ok", "ffmpeg": True}
14
-
15
- # -------- Custom Swagger /docs --------
16
- @app.get("/docs", include_in_schema=False)
17
- def custom_swagger():
18
- return get_swagger_ui_html(openapi_url="/openapi.json", title="FFmpeg API Docs")
19
-
20
- # -------- Trim Video Endpoint --------
21
- @app.post("/trim")
22
- async def trim(
23
- file: UploadFile = File(...),
24
- start: float = 0,
25
- duration: float = 5
26
- ):
27
  input_path = f"/tmp/{uuid.uuid4()}_in.mp4"
28
  output_path = f"/tmp/{uuid.uuid4()}_out.mp4"
29
 
30
- # Upload speichern
31
  with open(input_path, "wb") as f:
32
- f.write(await file.read())
33
 
34
  # FFmpeg Befehl ausführen
35
  cmd = [
36
- "ffmpeg", "-y",
 
37
  "-ss", str(start),
38
  "-i", input_path,
39
  "-t", str(duration),
@@ -42,9 +25,20 @@ async def trim(
42
  ]
43
  subprocess.run(cmd, check=True)
44
 
45
- # Output zurückgeben
46
- return FileResponse(
47
- output_path,
48
- media_type="video/mp4",
49
- filename="trimmed.mp4"
50
- )
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
 
 
2
  import subprocess
3
  import uuid
4
  import os
5
 
6
+ # -------- Video Trim Funktion --------
7
+ def trim_video(file, start, duration):
8
+ # Pfade für temporäre Dateien
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  input_path = f"/tmp/{uuid.uuid4()}_in.mp4"
10
  output_path = f"/tmp/{uuid.uuid4()}_out.mp4"
11
 
12
+ # Video speichern
13
  with open(input_path, "wb") as f:
14
+ f.write(file.read())
15
 
16
  # FFmpeg Befehl ausführen
17
  cmd = [
18
+ "ffmpeg",
19
+ "-y",
20
  "-ss", str(start),
21
  "-i", input_path,
22
  "-t", str(duration),
 
25
  ]
26
  subprocess.run(cmd, check=True)
27
 
28
+ return output_path
29
+
30
+ # -------- Gradio Interface --------
31
+ iface = gr.Interface(
32
+ fn=trim_video,
33
+ inputs=[
34
+ gr.File(label="Video hochladen", file_types=[".mp4"]),
35
+ gr.Number(label="Startzeit (Sekunden)", value=0),
36
+ gr.Number(label="Dauer (Sekunden)", value=5)
37
+ ],
38
+ outputs=gr.Video(label="Getrimmtes Video"),
39
+ title="FFmpeg Video Editor",
40
+ description="Trimme Videos direkt im Hugging Face Space"
41
+ )
42
+
43
+ # -------- Starten des Servers --------
44
+ iface.launch(server_name="0.0.0.0", server_port=7860)