Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,43 +1,45 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import os
|
| 3 |
import uuid
|
| 4 |
-
import shutil
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
| 11 |
-
"""
|
| 12 |
-
Função chamada tanto pela UI quanto pela API.
|
| 13 |
-
Recebe um arquivo e devolve um arquivo processado.
|
| 14 |
-
"""
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 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 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
description="Envie um vídeo e receba o arquivo processado.",
|
| 39 |
-
api_name="predict" # 👈 ISSO É O MAIS IMPORTANTE
|
| 40 |
-
)
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
|
|
|
| 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()
|