Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,12 +8,12 @@ def convert_webm_to_mp4(webm_file):
|
|
| 8 |
Recebe um arquivo WebM, converte para MP4 e retorna o caminho do MP4.
|
| 9 |
"""
|
| 10 |
if webm_file is None:
|
| 11 |
-
#
|
| 12 |
return "https://sample-videos.com/video123/mp4/240/big_buck_bunny_240p_1mb.mp4"
|
| 13 |
-
|
| 14 |
tmp_dir = tempfile.mkdtemp()
|
| 15 |
mp4_path = Path(tmp_dir) / "output.mp4"
|
| 16 |
-
|
| 17 |
try:
|
| 18 |
subprocess.run([
|
| 19 |
"ffmpeg",
|
|
@@ -26,22 +26,17 @@ def convert_webm_to_mp4(webm_file):
|
|
| 26 |
], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 27 |
except subprocess.CalledProcessError as e:
|
| 28 |
return f"Error converting video: {e.stderr.decode()}"
|
| 29 |
-
|
| 30 |
return mp4_path
|
| 31 |
|
| 32 |
-
# Interface
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
mp4_output = gr.Video(label="MP4 Output")
|
| 40 |
-
|
| 41 |
-
convert_btn = gr.Button("Convert")
|
| 42 |
-
|
| 43 |
-
# Handler Index 0
|
| 44 |
-
convert_btn.click(fn=convert_webm_to_mp4, inputs=[webm_input], outputs=[mp4_output])
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|
| 47 |
-
|
|
|
|
|
|
| 8 |
Recebe um arquivo WebM, converte para MP4 e retorna o caminho do MP4.
|
| 9 |
"""
|
| 10 |
if webm_file is None:
|
| 11 |
+
# MP4 dummy se nenhum WebM for enviado
|
| 12 |
return "https://sample-videos.com/video123/mp4/240/big_buck_bunny_240p_1mb.mp4"
|
| 13 |
+
|
| 14 |
tmp_dir = tempfile.mkdtemp()
|
| 15 |
mp4_path = Path(tmp_dir) / "output.mp4"
|
| 16 |
+
|
| 17 |
try:
|
| 18 |
subprocess.run([
|
| 19 |
"ffmpeg",
|
|
|
|
| 26 |
], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 27 |
except subprocess.CalledProcessError as e:
|
| 28 |
return f"Error converting video: {e.stderr.decode()}"
|
| 29 |
+
|
| 30 |
return mp4_path
|
| 31 |
|
| 32 |
+
# Interface explícita, compatível com App Builder
|
| 33 |
+
iface = gr.Interface(
|
| 34 |
+
fn=convert_webm_to_mp4,
|
| 35 |
+
inputs=gr.Video(label="WebM Input"),
|
| 36 |
+
outputs=gr.Video(label="MP4 Output"),
|
| 37 |
+
allow_flagging="never"
|
| 38 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
if __name__ == "__main__":
|
| 41 |
+
# Garantir que a primeira função do Space (Index 0) seja essa
|
| 42 |
+
iface.launch(server_name="0.0.0.0", server_port=7860, share=True)
|