Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,42 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
def convert_to_mp3(video_file):
|
| 6 |
if video_file is None:
|
| 7 |
return None
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
try:
|
| 13 |
-
#
|
| 14 |
-
video = VideoFileClip(video_file.name)
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
video.audio.write_audiofile(output_path, bitrate="320k")
|
| 19 |
|
| 20 |
-
#
|
| 21 |
video.close()
|
| 22 |
|
| 23 |
-
return
|
| 24 |
except Exception as e:
|
| 25 |
return f"Error en la conversión: {str(e)}"
|
| 26 |
|
| 27 |
-
# Interfaz
|
| 28 |
-
with gr.Blocks(theme=gr.themes.
|
| 29 |
-
gr.Markdown("# 🎵 Convertidor
|
| 30 |
-
gr.Markdown("
|
| 31 |
|
| 32 |
with gr.Row():
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
| 38 |
btn.click(fn=convert_to_mp3, inputs=video_input, outputs=audio_output)
|
| 39 |
|
| 40 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import moviepy as mp
|
| 3 |
import os
|
| 4 |
+
import time
|
| 5 |
|
| 6 |
def convert_to_mp3(video_file):
|
| 7 |
if video_file is None:
|
| 8 |
return None
|
| 9 |
|
| 10 |
+
# Generamos un nombre único basado en el tiempo para evitar conflictos
|
| 11 |
+
timestamp = int(time.time())
|
| 12 |
+
output_filename = f"audio_hd_{timestamp}.mp3"
|
| 13 |
|
| 14 |
try:
|
| 15 |
+
# Nueva forma de cargar el video en MoviePy 2.0+
|
| 16 |
+
video = mp.VideoFileClip(video_file.name)
|
| 17 |
|
| 18 |
+
# Extraer y guardar el audio con máxima calidad
|
| 19 |
+
video.audio.write_audiofile(output_filename, bitrate="320k", logger=None)
|
|
|
|
| 20 |
|
| 21 |
+
# Es vital cerrar el archivo para que Hugging Face pueda borrarlo después
|
| 22 |
video.close()
|
| 23 |
|
| 24 |
+
return output_filename
|
| 25 |
except Exception as e:
|
| 26 |
return f"Error en la conversión: {str(e)}"
|
| 27 |
|
| 28 |
+
# Interfaz estética
|
| 29 |
+
with gr.Blocks(theme=gr.themes.Default()) as demo:
|
| 30 |
+
gr.Markdown("# 🎵 Convertidor de Video a MP3 Pro")
|
| 31 |
+
gr.Markdown("Extrae audio en **320kbps** sin depender de internet ni sufrir bloqueos.")
|
| 32 |
|
| 33 |
with gr.Row():
|
| 34 |
+
with gr.Column():
|
| 35 |
+
video_input = gr.File(label="Sube tu video aquí", file_types=["video"])
|
| 36 |
+
btn = gr.Button("🔥 Convertir a MP3", variant="primary")
|
| 37 |
+
with gr.Column():
|
| 38 |
+
audio_output = gr.File(label="Tu MP3 de alta calidad")
|
| 39 |
+
|
| 40 |
btn.click(fn=convert_to_mp3, inputs=video_input, outputs=audio_output)
|
| 41 |
|
| 42 |
demo.launch()
|