Spaces:
Sleeping
Sleeping
| import torch | |
| import gradio as gr | |
| import yt_dlp as youtube_dl | |
| from transformers import pipeline | |
| from transformers.pipelines.audio_utils import ffmpeg_read | |
| import tempfile | |
| import os | |
| MODEL_NAME = "openai/whisper-large-v3-turbo" | |
| BATCH_SIZE = 8 | |
| FILE_LIMIT_MB = 1000 | |
| device = 0 if torch.cuda.is_available() else "cpu" | |
| pipe = pipeline( | |
| task="automatic-speech-recognition", | |
| model=MODEL_NAME, | |
| chunk_length_s=30, | |
| device=device, | |
| ) | |
| def transcribe(inputs, task): | |
| if inputs is None: | |
| raise gr.Error("No has subido ningún archivo de audio. Asegúrate de que tu archivo de audio es válido y vuelve a intentarlo.") | |
| text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"] | |
| return text | |
| demo = gr.Blocks() | |
| mf_transcribe = gr.Interface( | |
| fn=transcribe, | |
| inputs=[ | |
| gr.Audio(sources="microphone", type="filepath", label="Micrófono"), | |
| gr.Radio(["transcribe", "translate"], label="task", value="transcribe"), | |
| ], | |
| outputs="text", | |
| title="Whisper Large V3 Turbo: Transcribe en Español a la perfección y rápido", | |
| description=( | |
| "Aquí puedes hablar por el micrófono." | |
| ), | |
| allow_flagging="never", | |
| ) | |
| file_transcribe = gr.Interface( | |
| fn=transcribe, | |
| inputs=[ | |
| gr.Audio(sources="upload", type="filepath", label="Archivo de audio"), | |
| gr.Radio(["transcribe", "translate"], label="task", value="transcribe"), | |
| ], | |
| outputs="text", | |
| title="Whisper Large V3 Turbo: Transcribe en Español a la perfección y rápido", | |
| description=( | |
| "Aquí puedes pasar un archivo de audio ya grabado." | |
| ), | |
| allow_flagging="never", | |
| ) | |
| with demo: | |
| gr.TabbedInterface([mf_transcribe, file_transcribe], ["Micrófono", "Archivo de Audio"]) | |
| demo.queue().launch(debug=True) # share=True #ssr_mode = False |