AlexandreScriptsMT commited on
Commit
ad45296
·
verified ·
1 Parent(s): 3b6bdc0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -18
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
- # Retorna um 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,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 Gradio
33
- with gr.Blocks() as demo:
34
- gr.Markdown("### WebM to MP4 Converter\nUpload a WebM video and get MP4 back.")
35
-
36
- with gr.Row():
37
- # Aqui removemos `type="file"`
38
- webm_input = gr.Video(label="WebM Input")
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
- demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
 
 
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)