Spaces:
Sleeping
Sleeping
Add app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# 1) Pipeline de Whisper para ES → texto ES
|
6 |
+
device = 0 if torch.cuda.is_available() else -1
|
7 |
+
asr = pipeline(
|
8 |
+
"automatic-speech-recognition",
|
9 |
+
model="openai/whisper-medium",
|
10 |
+
device=device,
|
11 |
+
generate_kwargs={"task":"transcribe","language":"es"}
|
12 |
+
)
|
13 |
+
|
14 |
+
# 2) Función de transcripción
|
15 |
+
def transcribe(audio_path):
|
16 |
+
result = asr(audio_path)
|
17 |
+
return result["text"]
|
18 |
+
|
19 |
+
# 3) Interfaz Gradio
|
20 |
+
demo = gr.Interface(
|
21 |
+
fn=transcribe,
|
22 |
+
inputs=gr.Audio(source="upload", type="filepath", label="Sube audio (ES)"),
|
23 |
+
outputs=gr.Textbox(label="Transcripción"),
|
24 |
+
title="Audio→Texto en Español",
|
25 |
+
description="Transcribe audio en español con Whisper"
|
26 |
+
)
|
27 |
+
|
28 |
+
if __name__ == "__main__":
|
29 |
+
demo.launch()
|