Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
@@ -102,18 +102,18 @@ async def predict(
|
|
102 |
Levenshtein Distance Score from pitch and word
|
103 |
|
104 |
"""
|
105 |
-
upload_audio = ffmpeg_read(file, sampling_rate=16000)
|
106 |
audio_duration = len(upload_audio) / 16000
|
107 |
current_time = datetime.datetime.now().strftime("%Y-%h-%d-%H:%M:%S")
|
108 |
start_time = time.time()
|
109 |
-
error_message, score = None, None
|
110 |
-
|
111 |
-
if len(word) != len(pitch) and pitch
|
112 |
error_message = "Length of word and pitch input is not equal"
|
113 |
word_preds = query_raw(upload_audio, word, processor, processor_with_lm, quantized_model, temperature=temperature)
|
114 |
-
if pitch
|
115 |
pitch_preds = query_dummy(upload_audio, processor_pitch, quantized_pitch_model)
|
116 |
-
|
117 |
# find best word
|
118 |
word_score_list = []
|
119 |
for word_predict in word_preds:
|
@@ -123,16 +123,15 @@ async def predict(
|
|
123 |
wrong_word = find_different(word, best_word_predict) # get wrong word
|
124 |
|
125 |
# find best pitch
|
126 |
-
if
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
wrong_pitch = find_different(pitch, best_pitch_predict) # get wrong pitch
|
136 |
else:
|
137 |
score = int(word_score)
|
138 |
best_pitch_predict = None
|
|
|
102 |
Levenshtein Distance Score from pitch and word
|
103 |
|
104 |
"""
|
105 |
+
upload_audio = ffmpeg_read(file, sampling_rate=16000)
|
106 |
audio_duration = len(upload_audio) / 16000
|
107 |
current_time = datetime.datetime.now().strftime("%Y-%h-%d-%H:%M:%S")
|
108 |
start_time = time.time()
|
109 |
+
error_message, score , pitch_preds = None, None, None
|
110 |
+
|
111 |
+
if len(word) != len(pitch) and pitch is not None:
|
112 |
error_message = "Length of word and pitch input is not equal"
|
113 |
word_preds = query_raw(upload_audio, word, processor, processor_with_lm, quantized_model, temperature=temperature)
|
114 |
+
if pitch is not None:
|
115 |
pitch_preds = query_dummy(upload_audio, processor_pitch, quantized_pitch_model)
|
116 |
+
|
117 |
# find best word
|
118 |
word_score_list = []
|
119 |
for word_predict in word_preds:
|
|
|
123 |
wrong_word = find_different(word, best_word_predict) # get wrong word
|
124 |
|
125 |
# find best pitch
|
126 |
+
if pitch_preds is not None:
|
127 |
+
best_pitch_predict = pitch_preds.replace(" ", "")
|
128 |
+
if len(best_pitch_predict) < len(best_word_predict):
|
129 |
+
best_pitch_predict = best_pitch_predict + "1" * (len(best_word_predict) - len(best_pitch_predict))
|
130 |
+
else:
|
131 |
+
best_pitch_predict = best_pitch_predict[:len(best_word_predict)] # truncate to max len
|
132 |
+
pitch_score = fuzz.ratio(pitch, best_pitch_predict)
|
133 |
+
score = int((word_score * 2 + pitch_score) / 3)
|
134 |
+
wrong_pitch = find_different(pitch, best_pitch_predict) # get wrong pitch
|
|
|
135 |
else:
|
136 |
score = int(word_score)
|
137 |
best_pitch_predict = None
|