Spaces:
Runtime error
Runtime error
LordCoffee
commited on
Commit
•
1eb675b
1
Parent(s):
56b6854
Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,40 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
3 |
|
4 |
-
# Cargar el modelo Wav2Vec2
|
5 |
processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-large-960h-lv60-self")
|
6 |
-
|
7 |
-
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
fluency_score = evaluate_fluency(transcription)
|
19 |
-
|
20 |
return transcription, fluency_score
|
21 |
|
22 |
-
# Función para evaluar
|
23 |
-
def
|
24 |
-
#
|
25 |
-
|
|
|
|
|
26 |
return fluency_score
|
27 |
|
28 |
-
#
|
29 |
audio_input = gr.inputs.Audio(source="upload", type="file")
|
30 |
-
output_text = gr.outputs.Textbox()
|
31 |
-
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
fn=transcribe_and_evaluate,
|
36 |
inputs=audio_input,
|
37 |
-
outputs=[output_text,
|
38 |
-
title="
|
39 |
-
description="
|
40 |
-
)
|
41 |
-
|
42 |
-
# Ejecutar la interfaz de Gradio
|
43 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
|
4 |
|
5 |
+
# Cargar el modelo Wav2Vec2 y el procesador
|
6 |
processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-large-960h-lv60-self")
|
7 |
+
model = Wav2Vec2ForCTC.from_pretrained("facebook/wav2vec2-large-960h-lv60-self")
|
8 |
+
|
9 |
+
# Función para transcribir audio y evaluar la fluidez del texto
|
10 |
+
def evaluate_fluency(audio):
|
11 |
+
inputs = processor(audio, return_tensors="pt", sampling_rate=16_000).input_values
|
12 |
+
with torch.no_grad():
|
13 |
+
logits = model(inputs).logits
|
14 |
+
predicted_ids = torch.argmax(logits, dim=-1)
|
15 |
+
transcription = processor.batch_decode(predicted_ids)[0]
|
16 |
+
|
17 |
+
# Evaluar fluidez (métrica personalizada)
|
18 |
+
fluency_score = my_custom_fluency_metric(transcription)
|
|
|
|
|
19 |
return transcription, fluency_score
|
20 |
|
21 |
+
# Función de métrica personalizada para evaluar fluidez
|
22 |
+
def my_custom_fluency_metric(transcription):
|
23 |
+
# Implementa tu lógica para evaluar la fluidez del texto generado aquí
|
24 |
+
# Puedes usar métricas de NLP como ROUGE, BLEU o crear una métrica personalizada
|
25 |
+
# En este ejemplo, simplemente devuelve la longitud del texto como una métrica de "fluidez"
|
26 |
+
fluency_score = len(transcription.split())
|
27 |
return fluency_score
|
28 |
|
29 |
+
# Interfaz Gradio para la aplicación
|
30 |
audio_input = gr.inputs.Audio(source="upload", type="file")
|
31 |
+
output_text = gr.outputs.Textbox(label="Transcription")
|
32 |
+
output_score = gr.outputs.Textbox(label="Fluency Score")
|
33 |
|
34 |
+
gr.Interface(
|
35 |
+
fn=evaluate_fluency,
|
|
|
36 |
inputs=audio_input,
|
37 |
+
outputs=[output_text, output_score],
|
38 |
+
title="Audio Transcription & Fluency Evaluation",
|
39 |
+
description="Upload an audio file and evaluate transcription & fluency of the generated text."
|
40 |
+
).launch()
|
|
|
|
|
|