Update app.py
Browse files
app.py
CHANGED
|
@@ -43,29 +43,27 @@ def parse(wav_file):
|
|
| 43 |
|
| 44 |
|
| 45 |
# Function to retrieve an answer based on a question (using fuzzy matching)
|
| 46 |
-
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
#
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
# else:
|
| 68 |
-
# return "I don't have an answer to that question."
|
| 69 |
|
| 70 |
|
| 71 |
model_id = "jonatasgrosman/wav2vec2-large-xlsr-53-persian"
|
|
|
|
| 43 |
|
| 44 |
|
| 45 |
# Function to retrieve an answer based on a question (using fuzzy matching)
|
| 46 |
+
def get_answer(wav_file=None):
|
| 47 |
|
| 48 |
+
input_values = read_file_and_process(wav_file)
|
| 49 |
+
|
| 50 |
+
with torch.no_grad():
|
| 51 |
+
logits = model(**input_values).logits
|
| 52 |
+
user_question = parse_transcription(logits)
|
| 53 |
+
|
| 54 |
+
highest_score = 0
|
| 55 |
+
best_answer = None
|
| 56 |
+
|
| 57 |
+
for item in DATASET:
|
| 58 |
+
similarity_score = fuzz.token_set_ratio(user_question, item["question"])
|
| 59 |
+
if similarity_score > highest_score:
|
| 60 |
+
highest_score = similarity_score
|
| 61 |
+
best_answer = item["answer"]
|
| 62 |
+
|
| 63 |
+
if highest_score >= 80: # Adjust the similarity threshold as needed
|
| 64 |
+
return best_answer
|
| 65 |
+
else:
|
| 66 |
+
return "I don't have an answer to that question."
|
|
|
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
model_id = "jonatasgrosman/wav2vec2-large-xlsr-53-persian"
|