Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import gradio as gr
|
3 |
+
import yt_dlp as youtube_dl
|
4 |
+
from transformers import pipeline
|
5 |
+
from transformers.pipelines.audio_utils import ffmpeg_read
|
6 |
+
|
7 |
+
import tempfile
|
8 |
+
import os
|
9 |
+
|
10 |
+
MODEL_NAME = "openai/whisper-large-v3-turbo"
|
11 |
+
BATCH_SIZE = 8
|
12 |
+
FILE_LIMIT_MB = 1000
|
13 |
+
|
14 |
+
device = 0 if torch.cuda.is_available() else "cpu"
|
15 |
+
|
16 |
+
pipe = pipeline(
|
17 |
+
task="automatic-speech-recognition",
|
18 |
+
model=MODEL_NAME,
|
19 |
+
chunk_length_s=30,
|
20 |
+
device=device,
|
21 |
+
)
|
22 |
+
|
23 |
+
def transcribe(inputs, task):
|
24 |
+
if inputs is None:
|
25 |
+
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.")
|
26 |
+
|
27 |
+
text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
|
28 |
+
return text
|
29 |
+
|
30 |
+
|
31 |
+
demo = gr.Blocks()
|
32 |
+
|
33 |
+
mf_transcribe = gr.Interface(
|
34 |
+
fn=transcribe,
|
35 |
+
inputs=[
|
36 |
+
gr.Audio(sources="microphone", type="filepath", label="Micr贸fono"),
|
37 |
+
gr.Radio(["transcribe", "translate"], label="task", value="transcribe"),
|
38 |
+
],
|
39 |
+
outputs="text",
|
40 |
+
title="Whisper Large V3 Turbo: Transcribe en Espa帽ol a la perfecci贸n y r谩pido",
|
41 |
+
description=(
|
42 |
+
"Aqu铆 puedes hablar por el micr贸fono."
|
43 |
+
),
|
44 |
+
allow_flagging="never",
|
45 |
+
)
|
46 |
+
|
47 |
+
file_transcribe = gr.Interface(
|
48 |
+
fn=transcribe,
|
49 |
+
inputs=[
|
50 |
+
gr.Audio(sources="upload", type="filepath", label="Archivo de audio"),
|
51 |
+
gr.Radio(["transcribe", "translate"], label="task", value="transcribe"),
|
52 |
+
],
|
53 |
+
outputs="text",
|
54 |
+
title="Whisper Large V3 Turbo: Transcribe en Espa帽ol a la perfecci贸n y r谩pido",
|
55 |
+
description=(
|
56 |
+
"Aqu铆 puedes pasar un archivo de audio ya grabado."
|
57 |
+
),
|
58 |
+
allow_flagging="never",
|
59 |
+
)
|
60 |
+
|
61 |
+
with demo:
|
62 |
+
gr.TabbedInterface([mf_transcribe, file_transcribe], ["Micr贸fono", "Archivo de Audio"])
|
63 |
+
|
64 |
+
demo.queue().launch(debug=True) # share=True #ssr_mode = False
|