Update app.py
Browse files
app.py
CHANGED
|
@@ -34,38 +34,38 @@ def parse_transcription(logits):
|
|
| 34 |
return transcription
|
| 35 |
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 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 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
|
| 70 |
|
| 71 |
model_id = "jonatasgrosman/wav2vec2-large-xlsr-53-persian"
|
|
@@ -79,10 +79,10 @@ input_ = [
|
|
| 79 |
show_download_button=True,
|
| 80 |
show_edit_button=True,
|
| 81 |
),
|
| 82 |
-
gr.Textbox(label="سوال خود را بنویسید.",
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
]
|
| 87 |
|
| 88 |
txtbox = gr.Textbox(
|
|
@@ -97,7 +97,7 @@ title = "Speech-to-Text (persian)"
|
|
| 97 |
description = "، توجه داشته باشید که هرچه گفتار شما شمرده تر باشد خروجی با کیفیت تری دارید.روی دکمه ضبط صدا کلیک کنید و سپس دسترسی مرورگر خود را به میکروفون دستگاه بدهید، سپس شروع به صحبت کنید و برای اتمام ضبط دوباره روی دکمه کلیک کنید"
|
| 98 |
article = "<p style='text-align: center'><a href='https://github.com/nimaprgrmr'>Large-Scale Self- and Semi-Supervised Learning for Speech Translation</a></p>"
|
| 99 |
|
| 100 |
-
demo = gr.Interface(fn=
|
| 101 |
streaming=True, interactive=True,
|
| 102 |
analytics_enabled=False, show_tips=False, enable_queue=True)
|
| 103 |
demo.launch(share=True)
|
|
|
|
| 34 |
return transcription
|
| 35 |
|
| 36 |
|
| 37 |
+
def parse(wav_file):
|
| 38 |
+
input_values = read_file_and_process(wav_file)
|
| 39 |
+
with torch.no_grad():
|
| 40 |
+
logits = model(**input_values).logits
|
| 41 |
+
user_question = parse_transcription(logits)
|
| 42 |
+
return user_question
|
| 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"
|
|
|
|
| 79 |
show_download_button=True,
|
| 80 |
show_edit_button=True,
|
| 81 |
),
|
| 82 |
+
# gr.Textbox(label="سوال خود را بنویسید.",
|
| 83 |
+
# lines=3,
|
| 84 |
+
# text_align="right",
|
| 85 |
+
# show_label=True,)
|
| 86 |
]
|
| 87 |
|
| 88 |
txtbox = gr.Textbox(
|
|
|
|
| 97 |
description = "، توجه داشته باشید که هرچه گفتار شما شمرده تر باشد خروجی با کیفیت تری دارید.روی دکمه ضبط صدا کلیک کنید و سپس دسترسی مرورگر خود را به میکروفون دستگاه بدهید، سپس شروع به صحبت کنید و برای اتمام ضبط دوباره روی دکمه کلیک کنید"
|
| 98 |
article = "<p style='text-align: center'><a href='https://github.com/nimaprgrmr'>Large-Scale Self- and Semi-Supervised Learning for Speech Translation</a></p>"
|
| 99 |
|
| 100 |
+
demo = gr.Interface(fn=parse, inputs = input_, outputs=txtbox, title=title, description=description, article = article,
|
| 101 |
streaming=True, interactive=True,
|
| 102 |
analytics_enabled=False, show_tips=False, enable_queue=True)
|
| 103 |
demo.launch(share=True)
|