Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import subprocess
|
|
| 3 |
import uuid
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
# Diretório
|
| 7 |
OUTPUT_DIR = "outputs"
|
| 8 |
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 9 |
|
|
@@ -11,11 +11,11 @@ def webm_to_mp4(video_file):
|
|
| 11 |
"""
|
| 12 |
Recebe um arquivo WebM, converte para MP4 e retorna o caminho do arquivo.
|
| 13 |
"""
|
| 14 |
-
#
|
| 15 |
output_name = f"{uuid.uuid4()}.mp4"
|
| 16 |
output_path = os.path.join(OUTPUT_DIR, output_name)
|
| 17 |
|
| 18 |
-
#
|
| 19 |
subprocess.run(
|
| 20 |
[
|
| 21 |
"ffmpeg",
|
|
@@ -31,15 +31,18 @@ def webm_to_mp4(video_file):
|
|
| 31 |
|
| 32 |
return output_path
|
| 33 |
|
| 34 |
-
#
|
| 35 |
iface = gr.Interface(
|
| 36 |
fn=webm_to_mp4,
|
| 37 |
inputs=gr.File(file_types=[".webm"]),
|
| 38 |
outputs=gr.File(),
|
| 39 |
-
title="WebM → MP4
|
| 40 |
-
description="Envie um
|
| 41 |
-
api_name="convert"
|
| 42 |
)
|
| 43 |
|
| 44 |
# Inicializa o app
|
| 45 |
-
iface.launch(
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import uuid
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
# Diretório onde os vídeos convertidos serão salvos
|
| 7 |
OUTPUT_DIR = "outputs"
|
| 8 |
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 9 |
|
|
|
|
| 11 |
"""
|
| 12 |
Recebe um arquivo WebM, converte para MP4 e retorna o caminho do arquivo.
|
| 13 |
"""
|
| 14 |
+
# Gera nome único para o MP4
|
| 15 |
output_name = f"{uuid.uuid4()}.mp4"
|
| 16 |
output_path = os.path.join(OUTPUT_DIR, output_name)
|
| 17 |
|
| 18 |
+
# Executa o ffmpeg para converter WebM -> MP4
|
| 19 |
subprocess.run(
|
| 20 |
[
|
| 21 |
"ffmpeg",
|
|
|
|
| 31 |
|
| 32 |
return output_path
|
| 33 |
|
| 34 |
+
# Cria a interface Gradio
|
| 35 |
iface = gr.Interface(
|
| 36 |
fn=webm_to_mp4,
|
| 37 |
inputs=gr.File(file_types=[".webm"]),
|
| 38 |
outputs=gr.File(),
|
| 39 |
+
title="Conversor WebM → MP4",
|
| 40 |
+
description="Envie um arquivo WebM e receba o MP4 pronto para download.",
|
| 41 |
+
api_name="convert" # ← CRUCIAL para POST externo
|
| 42 |
)
|
| 43 |
|
| 44 |
# Inicializa o app
|
| 45 |
+
iface.launch(
|
| 46 |
+
server_name="0.0.0.0", # necessário no Hugging Face Space
|
| 47 |
+
server_port=7860
|
| 48 |
+
)
|