Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,43 +4,32 @@ import tempfile
|
|
| 4 |
import os
|
| 5 |
|
| 6 |
def convert_webm_to_mp4(webm_file):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
if webm_file is None:
|
| 8 |
return None
|
| 9 |
|
| 10 |
tmp_dir = tempfile.mkdtemp()
|
| 11 |
mp4_path = os.path.join(tmp_dir, "output.mp4")
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
"-i", webm_file,
|
| 19 |
-
"-c:v", "libx264",
|
| 20 |
-
"-preset", "fast",
|
| 21 |
-
"-crf", "23",
|
| 22 |
-
mp4_path
|
| 23 |
-
],
|
| 24 |
-
check=True,
|
| 25 |
-
stdout=subprocess.PIPE,
|
| 26 |
-
stderr=subprocess.PIPE
|
| 27 |
-
)
|
| 28 |
-
except subprocess.CalledProcessError as e:
|
| 29 |
-
return f"Erro ao converter: {e.stderr.decode()}"
|
| 30 |
|
| 31 |
return mp4_path
|
| 32 |
|
| 33 |
-
# --- Interface Gradio ---
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
# <-- aqui removemos 'type' -->
|
| 38 |
-
webm_input = gr.Video(label="Upload WebM")
|
| 39 |
-
mp4_output = gr.File(label="Download MP4")
|
| 40 |
-
convert_btn = gr.Button("Convert to MP4")
|
| 41 |
-
|
| 42 |
-
convert_btn.click(fn=convert_webm_to_mp4, inputs=[webm_input], outputs=[mp4_output])
|
| 43 |
-
|
| 44 |
-
# Rodar app
|
| 45 |
if __name__ == "__main__":
|
| 46 |
-
|
|
|
|
|
|
| 4 |
import os
|
| 5 |
|
| 6 |
def convert_webm_to_mp4(webm_file):
|
| 7 |
+
"""
|
| 8 |
+
Recebe um arquivo WebM enviado pelo App Builder,
|
| 9 |
+
converte para MP4 usando ffmpeg e retorna o caminho do arquivo MP4.
|
| 10 |
+
"""
|
| 11 |
if webm_file is None:
|
| 12 |
return None
|
| 13 |
|
| 14 |
tmp_dir = tempfile.mkdtemp()
|
| 15 |
mp4_path = os.path.join(tmp_dir, "output.mp4")
|
| 16 |
|
| 17 |
+
# Comando ffmpeg para conversão
|
| 18 |
+
subprocess.run(
|
| 19 |
+
["ffmpeg", "-y", "-i", webm_file, "-c:v", "libx264", mp4_path],
|
| 20 |
+
check=True
|
| 21 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
return mp4_path
|
| 24 |
|
| 25 |
+
# --- Interface Gradio compatível com App Builder ---
|
| 26 |
+
iface = gr.Interface(
|
| 27 |
+
fn=convert_webm_to_mp4,
|
| 28 |
+
inputs=gr.Video(label="Upload WebM"),
|
| 29 |
+
outputs=gr.File(label="Download MP4"),
|
| 30 |
+
allow_flagging="never" # desativa flags
|
| 31 |
+
)
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
if __name__ == "__main__":
|
| 34 |
+
# roda na porta 7860 e permite link público
|
| 35 |
+
iface.launch(server_name="0.0.0.0", server_port=7860, share=True)
|