Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,9 @@ def webm_to_mp4(video_file):
|
|
| 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)
|
|
@@ -31,18 +34,27 @@ def webm_to_mp4(video_file):
|
|
| 31 |
|
| 32 |
return output_path
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# Inicializa o app
|
| 45 |
-
|
| 46 |
-
server_name="0.0.0.0", # necessário no Hugging Face Space
|
| 47 |
-
server_port=7860
|
| 48 |
-
)
|
|
|
|
| 11 |
"""
|
| 12 |
Recebe um arquivo WebM, converte para MP4 e retorna o caminho do arquivo.
|
| 13 |
"""
|
| 14 |
+
if video_file is None:
|
| 15 |
+
return None
|
| 16 |
+
|
| 17 |
# Gera nome único para o MP4
|
| 18 |
output_name = f"{uuid.uuid4()}.mp4"
|
| 19 |
output_path = os.path.join(OUTPUT_DIR, output_name)
|
|
|
|
| 34 |
|
| 35 |
return output_path
|
| 36 |
|
| 37 |
+
# Criando o Blocks com API real
|
| 38 |
+
with gr.Blocks() as demo:
|
| 39 |
+
gr.Markdown("## Conversor WebM → MP4")
|
| 40 |
+
with gr.Row():
|
| 41 |
+
video_input = gr.File(label="Envie seu WebM", file_types=[".webm"])
|
| 42 |
+
output_file = gr.File(label="Download MP4")
|
| 43 |
+
|
| 44 |
+
convert_button = gr.Button("Converter")
|
| 45 |
+
loading_text = gr.Textbox(label="Status", interactive=False)
|
| 46 |
+
|
| 47 |
+
# Função de callback
|
| 48 |
+
def convert_and_update(video_file):
|
| 49 |
+
loading_text.value = "Convertendo..."
|
| 50 |
+
mp4_path = webm_to_mp4(video_file)
|
| 51 |
+
loading_text.value = "Concluído!"
|
| 52 |
+
return mp4_path
|
| 53 |
+
|
| 54 |
+
convert_button.click(fn=convert_and_update, inputs=video_input, outputs=output_file)
|
| 55 |
+
|
| 56 |
+
# Expondo API REST real
|
| 57 |
+
demo.api_name = "convert"
|
| 58 |
|
| 59 |
# Inicializa o app
|
| 60 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|