AlexandreScriptsMT commited on
Commit
33c4afa
·
verified ·
1 Parent(s): 1c02b32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -31
app.py CHANGED
@@ -1,43 +1,45 @@
1
  import gradio as gr
 
2
  import os
3
  import uuid
4
- import shutil
5
 
6
- # Pasta de saída
7
- OUTPUT_DIR = "outputs"
8
- os.makedirs(OUTPUT_DIR, exist_ok=True)
9
 
10
- def process_video(video_file):
11
- """
12
- Função chamada tanto pela UI quanto pela API.
13
- Recebe um arquivo e devolve um arquivo processado.
14
- """
15
 
16
- if video_file is None:
17
- raise ValueError("Nenhum arquivo enviado")
 
 
 
 
 
18
 
19
- # Nome único para evitar conflito
20
- file_id = str(uuid.uuid4())
21
- input_path = video_file
22
- output_path = os.path.join(OUTPUT_DIR, f"{file_id}_output.webm")
23
 
24
- # ⚠️ AQUI entra sua lógica real
25
- # Por enquanto, apenas copiamos o arquivo
26
- shutil.copy(input_path, output_path)
27
 
28
- # Retornar caminho do arquivo = link de download
29
- return output_path
 
 
 
 
 
 
 
 
 
30
 
 
31
 
32
- # 🔥 INTERFACE COM API EXPLÍCITA
33
- iface = gr.Interface(
34
- fn=process_video,
35
- inputs=gr.File(label="Upload do vídeo"),
36
- outputs=gr.File(label="Download do resultado"),
37
- title="Conversor de Vídeo",
38
- description="Envie um vídeo e receba o arquivo processado.",
39
- api_name="predict" # 👈 ISSO É O MAIS IMPORTANTE
40
- )
41
 
42
- if __name__ == "__main__":
43
- iface.launch()
 
1
  import gradio as gr
2
+ import subprocess
3
  import os
4
  import uuid
 
5
 
6
+ def convert_video(webm_file):
7
+ if webm_file is None:
8
+ return None
9
 
10
+ output_path = f"/tmp/{uuid.uuid4()}.mp4"
 
 
 
 
11
 
12
+ subprocess.run([
13
+ "ffmpeg", "-y",
14
+ "-i", webm_file,
15
+ "-movflags", "faststart",
16
+ "-pix_fmt", "yuv420p",
17
+ output_path
18
+ ], check=True)
19
 
20
+ return output_path
 
 
 
21
 
 
 
 
22
 
23
+ with gr.Blocks() as demo:
24
+ gr.Markdown("## WebM → MP4 Converter")
25
+
26
+ video_input = gr.File(
27
+ label="Upload WebM",
28
+ file_types=[".webm"]
29
+ )
30
+
31
+ video_output = gr.File(
32
+ label="MP4 Output"
33
+ )
34
 
35
+ convert_btn = gr.Button("Convert")
36
 
37
+ convert_btn.click(
38
+ fn=convert_video,
39
+ inputs=video_input,
40
+ outputs=video_output,
41
+ api_name="convert" # 🔥 ISSO É O QUE ESTAVA FALTANDO
42
+ )
 
 
 
43
 
44
+ demo.queue() # 🔥 OBRIGATÓRIO
45
+ demo.launch()