Update app.py
Browse files
app.py
CHANGED
@@ -43,12 +43,16 @@ def parse_transcription(logits):
|
|
43 |
|
44 |
|
45 |
# Function to retrieve an answer based on a question (using fuzzy matching)
|
46 |
-
def get_answer(wav_file):
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
52 |
highest_score = 0
|
53 |
best_answer = None
|
54 |
|
@@ -68,14 +72,21 @@ model_id = "jonatasgrosman/wav2vec2-large-xlsr-53-persian"
|
|
68 |
processor = Wav2Vec2Processor.from_pretrained(model_id)
|
69 |
model = Wav2Vec2ForCTC.from_pretrained(model_id)
|
70 |
|
71 |
-
input_ =
|
|
|
72 |
type="filepath",
|
73 |
label="لطفا دکمه ضبط صدا را بزنید و شروع به صحبت کنید و بعذ از اتمام صحبت دوباره دکمه ضبط را فشار دهید.",
|
74 |
show_download_button=True,
|
75 |
show_edit_button=True,
|
76 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
txtbox = gr.Textbox(
|
78 |
-
label="
|
79 |
lines=5,
|
80 |
text_align="right",
|
81 |
show_label=True,
|
|
|
43 |
|
44 |
|
45 |
# Function to retrieve an answer based on a question (using fuzzy matching)
|
46 |
+
def get_answer(wav_file, text=None):
|
47 |
+
|
48 |
+
if text=None:
|
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 |
+
elif text != None:
|
54 |
+
user_question = text
|
55 |
+
|
56 |
highest_score = 0
|
57 |
best_answer = None
|
58 |
|
|
|
72 |
processor = Wav2Vec2Processor.from_pretrained(model_id)
|
73 |
model = Wav2Vec2ForCTC.from_pretrained(model_id)
|
74 |
|
75 |
+
input_ = [
|
76 |
+
gr.Audio(source="microphone",
|
77 |
type="filepath",
|
78 |
label="لطفا دکمه ضبط صدا را بزنید و شروع به صحبت کنید و بعذ از اتمام صحبت دوباره دکمه ضبط را فشار دهید.",
|
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(
|
89 |
+
label="پاسخ شما: ",
|
90 |
lines=5,
|
91 |
text_align="right",
|
92 |
show_label=True,
|