Spaces:
Runtime error
Runtime error
LordCoffee
commited on
Commit
•
56b6854
1
Parent(s):
7af4a9f
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,43 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC, pipeline
|
3 |
|
4 |
+
# Cargar el modelo Wav2Vec2 para transcripción de audio
|
5 |
+
processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-large-960h-lv60-self")
|
6 |
+
model_wav2vec2 = Wav2Vec2ForCTC.from_pretrained("facebook/wav2vec2-large-960h-lv60-self")
|
7 |
+
|
8 |
+
# Cargar el modelo BART para generación de texto
|
9 |
+
generator = pipeline('text2text-generation', model='facebook/bart-large')
|
10 |
+
|
11 |
+
# Función para transcribir audio y evaluar fluidez
|
12 |
+
def transcribe_and_evaluate(audio):
|
13 |
+
input_values = processor(audio.read(), return_tensors="pt").input_values
|
14 |
+
logits = model_wav2vec2(input_values).logits
|
15 |
+
transcription = processor.batch_decode(torch.argmax(logits, dim=-1))
|
16 |
+
|
17 |
+
# Evaluar la fluidez del texto generado
|
18 |
+
fluency_score = evaluate_fluency(transcription)
|
19 |
+
|
20 |
+
return transcription, fluency_score
|
21 |
+
|
22 |
+
# Función para evaluar la fluidez del texto
|
23 |
+
def evaluate_fluency(text):
|
24 |
+
# Puedes implementar métricas más sofisticadas aquí si es necesario
|
25 |
+
fluency_score = len(text.split()) # Ejemplo simple: contar palabras
|
26 |
+
return fluency_score
|
27 |
+
|
28 |
+
# Configurar la interfaz de Gradio
|
29 |
+
audio_input = gr.inputs.Audio(source="upload", type="file")
|
30 |
+
output_text = gr.outputs.Textbox()
|
31 |
+
output_fluency = gr.outputs.Textbox()
|
32 |
+
|
33 |
+
# Definir la función de Gradio
|
34 |
+
iface = gr.Interface(
|
35 |
+
fn=transcribe_and_evaluate,
|
36 |
+
inputs=audio_input,
|
37 |
+
outputs=[output_text, output_fluency],
|
38 |
+
title="Transcripción de Audio y Evaluación de Fluidez",
|
39 |
+
description="Carga un archivo de audio y obtén la transcripción junto con el puntaje de fluidez del texto generado."
|
40 |
+
)
|
41 |
+
|
42 |
+
# Ejecutar la interfaz de Gradio
|
43 |
+
iface.launch()
|