Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import gradio as gr
|
|
5 |
import sox
|
6 |
import subprocess
|
7 |
from fuzzywuzzy import fuzz
|
|
|
8 |
|
9 |
|
10 |
def read_file_and_process(wav_file):
|
@@ -35,7 +36,26 @@ def parse(wav_file):
|
|
35 |
input_values = read_file_and_process(wav_file)
|
36 |
with torch.no_grad():
|
37 |
logits = model(**input_values).logits
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
model_id = "jonatasgrosman/wav2vec2-large-xlsr-53-persian"
|
41 |
processor = Wav2Vec2Processor.from_pretrained(model_id)
|
@@ -59,7 +79,7 @@ title = "Speech-to-Text (persian)"
|
|
59 |
description = "، توجه داشته باشید که هرچه گفتار شما شمرده تر باشد خروجی با کیفیت تری دارید.روی دکمه ضبط صدا کلیک کنید و سپس دسترسی مرورگر خود را به میکروفون دستگاه بدهید، سپس شروع به صحبت کنید و برای اتمام ضبط دوباره روی دکمه کلیک کنید"
|
60 |
article = "<p style='text-align: center'><a href='https://github.com/nimaprgrmr'>Large-Scale Self- and Semi-Supervised Learning for Speech Translation</a></p>"
|
61 |
|
62 |
-
demo = gr.Interface(fn=
|
63 |
streaming=True, interactive=True,
|
64 |
analytics_enabled=False, show_tips=False, enable_queue=True)
|
65 |
demo.launch(share=True)
|
|
|
5 |
import sox
|
6 |
import subprocess
|
7 |
from fuzzywuzzy import fuzz
|
8 |
+
from data import dataset
|
9 |
|
10 |
|
11 |
def read_file_and_process(wav_file):
|
|
|
36 |
input_values = read_file_and_process(wav_file)
|
37 |
with torch.no_grad():
|
38 |
logits = model(**input_values).logits
|
39 |
+
user_question = parse_transcription(logits)
|
40 |
+
return user_question
|
41 |
+
|
42 |
+
|
43 |
+
# Function to retrieve an answer based on a question (using fuzzy matching)
|
44 |
+
def get_answer(user_question):
|
45 |
+
highest_score = 0
|
46 |
+
best_answer = None
|
47 |
+
|
48 |
+
for item in dataset:
|
49 |
+
similarity_score = fuzz.token_set_ratio(user_question, item["question"])
|
50 |
+
if similarity_score > highest_score:
|
51 |
+
highest_score = similarity_score
|
52 |
+
best_answer = item["answer"]
|
53 |
+
|
54 |
+
if highest_score >= 80: # Adjust the similarity threshold as needed
|
55 |
+
return best_answer
|
56 |
+
else:
|
57 |
+
return "I don't have an answer to that question."
|
58 |
+
|
59 |
|
60 |
model_id = "jonatasgrosman/wav2vec2-large-xlsr-53-persian"
|
61 |
processor = Wav2Vec2Processor.from_pretrained(model_id)
|
|
|
79 |
description = "، توجه داشته باشید که هرچه گفتار شما شمرده تر باشد خروجی با کیفیت تری دارید.روی دکمه ضبط صدا کلیک کنید و سپس دسترسی مرورگر خود را به میکروفون دستگاه بدهید، سپس شروع به صحبت کنید و برای اتمام ضبط دوباره روی دکمه کلیک کنید"
|
80 |
article = "<p style='text-align: center'><a href='https://github.com/nimaprgrmr'>Large-Scale Self- and Semi-Supervised Learning for Speech Translation</a></p>"
|
81 |
|
82 |
+
demo = gr.Interface(fn=get_answer, inputs = input_, outputs=txtbox, title=title, description=description, article = article,
|
83 |
streaming=True, interactive=True,
|
84 |
analytics_enabled=False, show_tips=False, enable_queue=True)
|
85 |
demo.launch(share=True)
|