Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,9 +4,24 @@ from transformers import pipeline
|
|
4 |
from jiwer import wer
|
5 |
|
6 |
# Load models
|
7 |
-
whisper_pipeline_1 = pipeline(
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
def transcribe_and_compare(audio_path, original_transcription=None):
|
12 |
"""
|
@@ -18,27 +33,30 @@ def transcribe_and_compare(audio_path, original_transcription=None):
|
|
18 |
Returns:
|
19 |
dict: Results including transcriptions and WER calculations.
|
20 |
"""
|
|
|
21 |
transcription_1 = whisper_pipeline_1(audio_path)["text"]
|
22 |
transcription_2 = whisper_pipeline_2(audio_path)["text"]
|
23 |
transcription_3 = whisper_pipeline_3(audio_path)["text"]
|
24 |
|
|
|
25 |
comparison_result = {
|
26 |
"Model 1 Output (maliahson/Finetuned_Whisper_Medium_Model_2)": transcription_1,
|
27 |
"Model 2 Output (openai/whisper-large-v3-turbo)": transcription_2,
|
28 |
-
"Model 3 Output (Openai/whisper-medium)": transcription_3
|
29 |
}
|
30 |
|
31 |
if original_transcription:
|
32 |
-
# Calculate Word Error Rate (WER)
|
33 |
wer_1 = wer(original_transcription, transcription_1)
|
34 |
wer_2 = wer(original_transcription, transcription_2)
|
35 |
wer_3 = wer(original_transcription, transcription_3)
|
36 |
|
|
|
37 |
comparison_result["WER Model 1"] = wer_1
|
38 |
comparison_result["WER Model 2"] = wer_2
|
39 |
comparison_result["WER Model 3"] = wer_3
|
40 |
else:
|
41 |
-
# Compare outputs of all three models
|
42 |
comparison_result["Difference Between Models"] = {
|
43 |
"Model 1 Unique Words": set(transcription_1.split()) - set(transcription_2.split()) - set(transcription_3.split()),
|
44 |
"Model 2 Unique Words": set(transcription_2.split()) - set(transcription_1.split()) - set(transcription_3.split()),
|
|
|
4 |
from jiwer import wer
|
5 |
|
6 |
# Load models
|
7 |
+
whisper_pipeline_1 = pipeline(
|
8 |
+
"automatic-speech-recognition",
|
9 |
+
model="maliahson/Finetuned_Whisper_Medium_Model_2"
|
10 |
+
)
|
11 |
+
|
12 |
+
whisper_pipeline_2 = pipeline(
|
13 |
+
"automatic-speech-recognition",
|
14 |
+
model="openai/whisper-large-v3-turbo",
|
15 |
+
device=0 if torch.cuda.is_available() else "cpu"
|
16 |
+
)
|
17 |
+
|
18 |
+
whisper_pipeline_3 = pipeline(
|
19 |
+
"automatic-speech-recognition",
|
20 |
+
model="openai/whisper-medium",
|
21 |
+
device=0 if torch.cuda.is_available() else "cpu",
|
22 |
+
# Explicitly set language and task for Urdu transcription
|
23 |
+
model_kwargs={"language": "<|ur|>", "task": "transcribe"}
|
24 |
+
)
|
25 |
|
26 |
def transcribe_and_compare(audio_path, original_transcription=None):
|
27 |
"""
|
|
|
33 |
Returns:
|
34 |
dict: Results including transcriptions and WER calculations.
|
35 |
"""
|
36 |
+
# Transcriptions from all three models
|
37 |
transcription_1 = whisper_pipeline_1(audio_path)["text"]
|
38 |
transcription_2 = whisper_pipeline_2(audio_path)["text"]
|
39 |
transcription_3 = whisper_pipeline_3(audio_path)["text"]
|
40 |
|
41 |
+
# Prepare comparison results
|
42 |
comparison_result = {
|
43 |
"Model 1 Output (maliahson/Finetuned_Whisper_Medium_Model_2)": transcription_1,
|
44 |
"Model 2 Output (openai/whisper-large-v3-turbo)": transcription_2,
|
45 |
+
"Model 3 Output (Openai/whisper-medium, Urdu)": transcription_3
|
46 |
}
|
47 |
|
48 |
if original_transcription:
|
49 |
+
# Calculate Word Error Rate (WER) for all models
|
50 |
wer_1 = wer(original_transcription, transcription_1)
|
51 |
wer_2 = wer(original_transcription, transcription_2)
|
52 |
wer_3 = wer(original_transcription, transcription_3)
|
53 |
|
54 |
+
# Add WER scores to results
|
55 |
comparison_result["WER Model 1"] = wer_1
|
56 |
comparison_result["WER Model 2"] = wer_2
|
57 |
comparison_result["WER Model 3"] = wer_3
|
58 |
else:
|
59 |
+
# Compare outputs of all three models when no ground truth is provided
|
60 |
comparison_result["Difference Between Models"] = {
|
61 |
"Model 1 Unique Words": set(transcription_1.split()) - set(transcription_2.split()) - set(transcription_3.split()),
|
62 |
"Model 2 Unique Words": set(transcription_2.split()) - set(transcription_1.split()) - set(transcription_3.split()),
|