Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from transformers import pipeline
|
|
|
4 |
|
5 |
# Load models
|
6 |
whisper_pipeline_1 = pipeline("automatic-speech-recognition", model="maliahson/whisper-agri")
|
@@ -8,23 +9,42 @@ device = 0 if torch.cuda.is_available() else "cpu"
|
|
8 |
whisper_pipeline_2 = pipeline("automatic-speech-recognition", model="openai/whisper-large-v3-turbo", device=device)
|
9 |
|
10 |
def transcribe_and_compare(audio_path, original_transcription=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
transcription_1 = whisper_pipeline_1(audio_path)["text"]
|
12 |
transcription_2 = whisper_pipeline_2(audio_path)["text"]
|
13 |
-
comparison_result = {
|
|
|
|
|
|
|
14 |
|
15 |
if original_transcription:
|
16 |
-
|
17 |
wer_1 = wer(original_transcription, transcription_1)
|
18 |
wer_2 = wer(original_transcription, transcription_2)
|
19 |
comparison_result["WER Model 1"] = wer_1
|
20 |
comparison_result["WER Model 2"] = wer_2
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
return comparison_result
|
23 |
|
24 |
# Gradio Interface
|
25 |
with gr.Blocks() as demo:
|
26 |
gr.Markdown("## Audio Transcription and Comparison")
|
27 |
-
audio_input = gr.Audio(type="filepath", label="Upload or Record Audio
|
28 |
original_transcription = gr.Textbox(lines=2, label="Original Transcription (Optional)")
|
29 |
output = gr.JSON(label="Comparison Results")
|
30 |
submit_btn = gr.Button("Transcribe and Compare")
|
@@ -35,4 +55,4 @@ with gr.Blocks() as demo:
|
|
35 |
outputs=output
|
36 |
)
|
37 |
|
38 |
-
demo.launch(debug=True)
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from transformers import pipeline
|
4 |
+
from jiwer import wer
|
5 |
|
6 |
# Load models
|
7 |
whisper_pipeline_1 = pipeline("automatic-speech-recognition", model="maliahson/whisper-agri")
|
|
|
9 |
whisper_pipeline_2 = pipeline("automatic-speech-recognition", model="openai/whisper-large-v3-turbo", device=device)
|
10 |
|
11 |
def transcribe_and_compare(audio_path, original_transcription=None):
|
12 |
+
"""
|
13 |
+
Transcribes an audio file using two Whisper models and compares results.
|
14 |
+
|
15 |
+
Args:
|
16 |
+
audio_path (str): Path to the audio file.
|
17 |
+
original_transcription (str, optional): Ground truth transcription.
|
18 |
+
|
19 |
+
Returns:
|
20 |
+
dict: Results including transcriptions and WER calculations.
|
21 |
+
"""
|
22 |
transcription_1 = whisper_pipeline_1(audio_path)["text"]
|
23 |
transcription_2 = whisper_pipeline_2(audio_path)["text"]
|
24 |
+
comparison_result = {
|
25 |
+
"Model 1 Output (maliahson/whisper-agri)": transcription_1,
|
26 |
+
"Model 2 Output (openai/whisper-large-v3-turbo)": transcription_2,
|
27 |
+
}
|
28 |
|
29 |
if original_transcription:
|
30 |
+
# Calculate Word Error Rate
|
31 |
wer_1 = wer(original_transcription, transcription_1)
|
32 |
wer_2 = wer(original_transcription, transcription_2)
|
33 |
comparison_result["WER Model 1"] = wer_1
|
34 |
comparison_result["WER Model 2"] = wer_2
|
35 |
+
else:
|
36 |
+
# Compare outputs of both models
|
37 |
+
comparison_result["Difference Between Models"] = {
|
38 |
+
"Model 1 Unique Words": set(transcription_1.split()) - set(transcription_2.split()),
|
39 |
+
"Model 2 Unique Words": set(transcription_2.split()) - set(transcription_1.split()),
|
40 |
+
}
|
41 |
|
42 |
return comparison_result
|
43 |
|
44 |
# Gradio Interface
|
45 |
with gr.Blocks() as demo:
|
46 |
gr.Markdown("## Audio Transcription and Comparison")
|
47 |
+
audio_input = gr.Audio(type="filepath", label="Upload or Record Audio")
|
48 |
original_transcription = gr.Textbox(lines=2, label="Original Transcription (Optional)")
|
49 |
output = gr.JSON(label="Comparison Results")
|
50 |
submit_btn = gr.Button("Transcribe and Compare")
|
|
|
55 |
outputs=output
|
56 |
)
|
57 |
|
58 |
+
demo.launch(debug=True)
|