Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,27 @@
|
|
| 1 |
-
|
| 2 |
-
from
|
| 3 |
-
import
|
| 4 |
-
from io import BytesIO
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
img = Image.open(BytesIO(response.content))
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
|
| 3 |
+
import torch
|
|
|
|
| 4 |
|
| 5 |
+
# Cargar el modelo y el procesador
|
| 6 |
+
model = Wav2Vec2ForCTC.from_pretrained("openai/whisper-large-v2")
|
| 7 |
+
processor = Wav2Vec2Processor.from_pretrained("openai/whisper-large-v2")
|
| 8 |
|
| 9 |
+
def asr(audio_file_path):
|
| 10 |
+
# Cargar archivo de audio
|
| 11 |
+
input_audio, _ = librosa.load(audio_file_path, sr=16000)
|
| 12 |
|
| 13 |
+
# Preprocesar audio
|
| 14 |
+
input_values = processor(input_audio, return_tensors="pt", sampling_rate=16000).input_values
|
|
|
|
| 15 |
|
| 16 |
+
# Realizar inferencia
|
| 17 |
+
logits = model(input_values).logits
|
| 18 |
|
| 19 |
+
# Decodificar los logits a texto
|
| 20 |
+
predicted_ids = torch.argmax(logits, dim=-1)
|
| 21 |
+
transcription = processor.decode(predicted_ids[0])
|
| 22 |
|
| 23 |
+
return transcription
|
| 24 |
+
|
| 25 |
+
# Crear interfaz de Gradio
|
| 26 |
+
iface = gr.Interface(fn=asr, inputs=gr.inputs.Audio(source="microphone", type="file"), outputs="text")
|
| 27 |
+
iface.launch()
|