Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ import os
|
|
8 |
import transformers
|
9 |
from transformers import pipeline, WhisperForConditionalGeneration, WhisperTokenizer, WhisperFeatureExtractor
|
10 |
import time
|
|
|
11 |
|
12 |
# def greet_from_secret(ignored_param):
|
13 |
# name = os.environ.get('TOKEN')
|
@@ -34,9 +35,16 @@ tokenizer3 = WhisperTokenizer.from_pretrained(M3, use_auth_token=auth_token)
|
|
34 |
feat_ext3 = WhisperFeatureExtractor.from_pretrained(M3, use_auth_token=auth_token)
|
35 |
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
p1 = pipeline('automatic-speech-recognition', model=model1, tokenizer=tokenizer1, feature_extractor=feat_ext1)
|
38 |
p2 = pipeline('automatic-speech-recognition', model=model2, tokenizer=tokenizer2, feature_extractor=feat_ext2)
|
39 |
p3 = pipeline('automatic-speech-recognition', model=model3, tokenizer=tokenizer3, feature_extractor=feat_ext3)
|
|
|
40 |
|
41 |
def transcribe(mic_input, upl_input, model_type):
|
42 |
if mic_input:
|
@@ -49,6 +57,8 @@ def transcribe(mic_input, upl_input, model_type):
|
|
49 |
text = p2(audio)["text"]
|
50 |
elif model_type == 'CleanFinetuned':
|
51 |
text = p3(audio)["text"]
|
|
|
|
|
52 |
else:
|
53 |
text = p1(audio)["text"]
|
54 |
end_time = time.time()
|
@@ -105,7 +115,7 @@ if __name__ == "__main__":
|
|
105 |
)
|
106 |
|
107 |
with gr.Row():
|
108 |
-
model_type = gr.inputs.Dropdown(["RobustDistillation", "NoisyFinetuned", "CleanFinetuned"], label='Model Type')
|
109 |
|
110 |
with gr.Row():
|
111 |
clr_btn = gr.Button(value="Clear", variant="secondary")
|
|
|
8 |
import transformers
|
9 |
from transformers import pipeline, WhisperForConditionalGeneration, WhisperTokenizer, WhisperFeatureExtractor
|
10 |
import time
|
11 |
+
import torch
|
12 |
|
13 |
# def greet_from_secret(ignored_param):
|
14 |
# name = os.environ.get('TOKEN')
|
|
|
35 |
feat_ext3 = WhisperFeatureExtractor.from_pretrained(M3, use_auth_token=auth_token)
|
36 |
|
37 |
|
38 |
+
# make quantized model
|
39 |
+
quantized_model1 = torch.quantization.quantize_dynamic(
|
40 |
+
model3, {torch.nn.Linear}, dtype=torch.qint8
|
41 |
+
)
|
42 |
+
|
43 |
+
|
44 |
p1 = pipeline('automatic-speech-recognition', model=model1, tokenizer=tokenizer1, feature_extractor=feat_ext1)
|
45 |
p2 = pipeline('automatic-speech-recognition', model=model2, tokenizer=tokenizer2, feature_extractor=feat_ext2)
|
46 |
p3 = pipeline('automatic-speech-recognition', model=model3, tokenizer=tokenizer3, feature_extractor=feat_ext3)
|
47 |
+
p1_quant = pipeline('automatic-speech-recognition', model=model1, tokenizer=tokenizer1, feature_extractor=feat_ext1)
|
48 |
|
49 |
def transcribe(mic_input, upl_input, model_type):
|
50 |
if mic_input:
|
|
|
57 |
text = p2(audio)["text"]
|
58 |
elif model_type == 'CleanFinetuned':
|
59 |
text = p3(audio)["text"]
|
60 |
+
elif model_type == 'NoisyDistillationQuantised':
|
61 |
+
text = p1_quant(audio)['text']
|
62 |
else:
|
63 |
text = p1(audio)["text"]
|
64 |
end_time = time.time()
|
|
|
115 |
)
|
116 |
|
117 |
with gr.Row():
|
118 |
+
model_type = gr.inputs.Dropdown(["RobustDistillation", "NoisyFinetuned", "CleanFinetuned", "NoisyDistillationQuantised"], label='Model Type')
|
119 |
|
120 |
with gr.Row():
|
121 |
clr_btn = gr.Button(value="Clear", variant="secondary")
|