nimool commited on
Commit
b9b4130
·
1 Parent(s): da5b65e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -22
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
- # def get_answer(wav_file=None, text=None):
47
 
48
- # if type(wav_file) != 'str' or type(text != 'str'):
49
- # input_values = read_file_and_process(wav_file)
50
- # with torch.no_grad():
51
- # logits = model(**input_values).logits
52
- # user_question = parse_transcription(logits)
53
- # else:
54
- # user_question = wav_file
55
-
56
- # highest_score = 0
57
- # best_answer = None
58
-
59
- # for item in DATASET:
60
- # similarity_score = fuzz.token_set_ratio(user_question, item["question"])
61
- # if similarity_score > highest_score:
62
- # highest_score = similarity_score
63
- # best_answer = item["answer"]
64
-
65
- # if highest_score >= 80: # Adjust the similarity threshold as needed
66
- # return best_answer
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"