Update app.py
Browse files
app.py
CHANGED
@@ -21,7 +21,7 @@ def clean_up_memory():
|
|
21 |
gc.collect()
|
22 |
torch.cuda.empty_cache()
|
23 |
|
24 |
-
@spaces.GPU
|
25 |
def recap_sentence(string):
|
26 |
# Restore capitalization and punctuation using the model
|
27 |
inputs = recap_tokenizer(["restore capitalization and punctuation: " + string], return_tensors="pt", padding=True).to(device)
|
@@ -29,15 +29,15 @@ def recap_sentence(string):
|
|
29 |
recap_result = recap_tokenizer.decode(outputs, skip_special_tokens=True)
|
30 |
return recap_result
|
31 |
|
32 |
-
|
33 |
def return_prediction_w2v2(mic=None, file=None, device=device):
|
34 |
if mic is not None:
|
35 |
waveform, sr = librosa.load(mic, sr=16000)
|
36 |
-
waveform = waveform[:
|
37 |
w2v2_result = w2v2_classifier.classify_file_w2v2(waveform, device)
|
38 |
elif file is not None:
|
39 |
waveform, sr = librosa.load(file, sr=16000)
|
40 |
-
waveform = waveform[:
|
41 |
w2v2_result = w2v2_classifier.classify_file_w2v2(waveform, device)
|
42 |
else:
|
43 |
return "You must either provide a mic recording or a file"
|
@@ -57,11 +57,11 @@ def return_prediction_w2v2(mic=None, file=None, device=device):
|
|
57 |
def return_prediction_whisper(mic=None, file=None, device=device):
|
58 |
if mic is not None:
|
59 |
waveform, sr = librosa.load(mic, sr=16000)
|
60 |
-
waveform = waveform[:
|
61 |
whisper_result = whisper_classifier.classify_file_whisper_mkd(waveform, device)
|
62 |
elif file is not None:
|
63 |
waveform, sr = librosa.load(file, sr=16000)
|
64 |
-
waveform = waveform[:
|
65 |
whisper_result = whisper_classifier.classify_file_whisper_mkd(waveform, device)
|
66 |
else:
|
67 |
return "You must either provide a mic recording or a file"
|
@@ -83,7 +83,7 @@ def return_prediction_compare(mic=None, file=None, device=device):
|
|
83 |
# mms_model.to(device)
|
84 |
if mic is not None:
|
85 |
waveform, sr = librosa.load(mic, sr=16000)
|
86 |
-
waveform = waveform[:
|
87 |
whisper_mkd_result = whisper_classifier.classify_file_whisper_mkd(waveform, device)
|
88 |
# result_generator_w2v2 = w2v2_classifier.classify_file_w2v2(mic, device)
|
89 |
whisper_result = whisper_classifier.classify_file_whisper(waveform, pipe_whisper, device)
|
@@ -91,7 +91,7 @@ def return_prediction_compare(mic=None, file=None, device=device):
|
|
91 |
|
92 |
elif file is not None:
|
93 |
waveform, sr = librosa.load(file, sr=16000)
|
94 |
-
waveform = waveform[:
|
95 |
whisper_mkd_result = whisper_classifier.classify_file_whisper_mkd(waveform, device)
|
96 |
# result_generator_w2v2 = w2v2_classifier.classify_file_w2v2(file, device)
|
97 |
whisper_result = whisper_classifier.classify_file_whisper(waveform, pipe_whisper, device)
|
|
|
21 |
gc.collect()
|
22 |
torch.cuda.empty_cache()
|
23 |
|
24 |
+
@spaces.GPU(duration=30)
|
25 |
def recap_sentence(string):
|
26 |
# Restore capitalization and punctuation using the model
|
27 |
inputs = recap_tokenizer(["restore capitalization and punctuation: " + string], return_tensors="pt", padding=True).to(device)
|
|
|
29 |
recap_result = recap_tokenizer.decode(outputs, skip_special_tokens=True)
|
30 |
return recap_result
|
31 |
|
32 |
+
|
33 |
def return_prediction_w2v2(mic=None, file=None, device=device):
|
34 |
if mic is not None:
|
35 |
waveform, sr = librosa.load(mic, sr=16000)
|
36 |
+
waveform = waveform[:120*sr]
|
37 |
w2v2_result = w2v2_classifier.classify_file_w2v2(waveform, device)
|
38 |
elif file is not None:
|
39 |
waveform, sr = librosa.load(file, sr=16000)
|
40 |
+
waveform = waveform[:120*sr]
|
41 |
w2v2_result = w2v2_classifier.classify_file_w2v2(waveform, device)
|
42 |
else:
|
43 |
return "You must either provide a mic recording or a file"
|
|
|
57 |
def return_prediction_whisper(mic=None, file=None, device=device):
|
58 |
if mic is not None:
|
59 |
waveform, sr = librosa.load(mic, sr=16000)
|
60 |
+
waveform = waveform[:120*sr]
|
61 |
whisper_result = whisper_classifier.classify_file_whisper_mkd(waveform, device)
|
62 |
elif file is not None:
|
63 |
waveform, sr = librosa.load(file, sr=16000)
|
64 |
+
waveform = waveform[:120*sr]
|
65 |
whisper_result = whisper_classifier.classify_file_whisper_mkd(waveform, device)
|
66 |
else:
|
67 |
return "You must either provide a mic recording or a file"
|
|
|
83 |
# mms_model.to(device)
|
84 |
if mic is not None:
|
85 |
waveform, sr = librosa.load(mic, sr=16000)
|
86 |
+
waveform = waveform[:120*sr]
|
87 |
whisper_mkd_result = whisper_classifier.classify_file_whisper_mkd(waveform, device)
|
88 |
# result_generator_w2v2 = w2v2_classifier.classify_file_w2v2(mic, device)
|
89 |
whisper_result = whisper_classifier.classify_file_whisper(waveform, pipe_whisper, device)
|
|
|
91 |
|
92 |
elif file is not None:
|
93 |
waveform, sr = librosa.load(file, sr=16000)
|
94 |
+
waveform = waveform[:120*sr]
|
95 |
whisper_mkd_result = whisper_classifier.classify_file_whisper_mkd(waveform, device)
|
96 |
# result_generator_w2v2 = w2v2_classifier.classify_file_w2v2(file, device)
|
97 |
whisper_result = whisper_classifier.classify_file_whisper(waveform, pipe_whisper, device)
|