Update app.py
Browse files
app.py
CHANGED
@@ -25,12 +25,13 @@ print(dataset, "and at 0[audio][array] ", dataset[0]["audio"]["array"], type(dat
|
|
25 |
|
26 |
def transcribe(audio):
|
27 |
text = pipe(audio)["text"]
|
28 |
-
|
|
|
29 |
|
30 |
iface = gr.Interface(
|
31 |
fn=transcribe,
|
32 |
inputs=gr.Audio(source="microphone", type="filepath"),
|
33 |
-
outputs="text",
|
34 |
title="Whisper Small Miso Test",
|
35 |
)
|
36 |
|
@@ -39,50 +40,7 @@ iface.launch()
|
|
39 |
def evalWhisper(model, dataset):
|
40 |
model.eval()
|
41 |
print("model.eval ", model.eval())
|
42 |
-
|
43 |
-
# Define a list to store the print statements
|
44 |
-
log_texts = []
|
45 |
-
|
46 |
-
with torch.no_grad():
|
47 |
-
outputs = model(**input_data) # Define input_data appropriately
|
48 |
-
print("outputs ", outputs)
|
49 |
-
log_texts.append(f"outputs: {outputs}")
|
50 |
-
|
51 |
-
# Convert predicted token IDs back to text
|
52 |
-
predicted_text = tokenizer.batch_decode(outputs.logits.argmax(dim=-1), skip_special_tokens=True)
|
53 |
-
|
54 |
-
# Get ground truth labels from the dataset
|
55 |
-
labels = dataset["audio"] # Replace "labels" with the appropriate key in your dataset
|
56 |
-
print("labels are ", labels)
|
57 |
-
log_texts.append(f"labels: {labels}")
|
58 |
-
|
59 |
-
# Compute WER
|
60 |
-
wer_score = wer(labels, predicted_text) # Define wer function
|
61 |
-
|
62 |
-
# Print or return WER score
|
63 |
-
wer_message = f"Word Error Rate (WER): {wer_score}"
|
64 |
-
print(wer_message)
|
65 |
-
log_texts.append(wer_message)
|
66 |
-
|
67 |
-
print(log_texts)
|
68 |
-
|
69 |
-
return log_texts
|
70 |
-
|
71 |
-
# Call evalWhisper and get the log texts
|
72 |
-
log_texts = evalWhisper(model, dataset)
|
73 |
|
74 |
-
# Display the log texts using gr.Interface
|
75 |
-
log_text = "\n".join(log_texts)
|
76 |
-
log_interface = gr.Interface(
|
77 |
-
fn=lambda: log_text,
|
78 |
-
inputs=None,
|
79 |
-
outputs="text",
|
80 |
-
title="EvalWhisper Log",
|
81 |
-
)
|
82 |
-
log_interface.launch()
|
83 |
-
|
84 |
-
|
85 |
-
'''
|
86 |
# Evaluate the model
|
87 |
model.eval()
|
88 |
print("model.eval ", model.eval())
|
@@ -102,7 +60,7 @@ log_interface.launch()
|
|
102 |
|
103 |
# Print or return WER score
|
104 |
print(f"Word Error Rate (WER): {wer_score}")
|
105 |
-
|
106 |
'''
|
107 |
print("check check")
|
108 |
print(inputs)
|
|
|
25 |
|
26 |
def transcribe(audio):
|
27 |
text = pipe(audio)["text"]
|
28 |
+
test = evalWhisper(model, dataset)
|
29 |
+
return text, test
|
30 |
|
31 |
iface = gr.Interface(
|
32 |
fn=transcribe,
|
33 |
inputs=gr.Audio(source="microphone", type="filepath"),
|
34 |
+
outputs="text", "text"
|
35 |
title="Whisper Small Miso Test",
|
36 |
)
|
37 |
|
|
|
40 |
def evalWhisper(model, dataset):
|
41 |
model.eval()
|
42 |
print("model.eval ", model.eval())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
# Evaluate the model
|
45 |
model.eval()
|
46 |
print("model.eval ", model.eval())
|
|
|
60 |
|
61 |
# Print or return WER score
|
62 |
print(f"Word Error Rate (WER): {wer_score}")
|
63 |
+
|
64 |
'''
|
65 |
print("check check")
|
66 |
print(inputs)
|