Spaces:
Runtime error
Runtime error
RamAnanth1
commited on
Commit
·
4094da1
1
Parent(s):
49faccd
Update app.py
Browse files
app.py
CHANGED
@@ -19,9 +19,15 @@ whisper_model = pipeline(
|
|
19 |
device=device,
|
20 |
)
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
def get_response_from_chatbot(text):
|
27 |
try:
|
@@ -147,18 +153,18 @@ with gr.Blocks(title='Talk to chatGPT') as demo:
|
|
147 |
chatbot = gr.Chatbot(elem_id="chat_bot", visible=False).style(color_map=("green", "blue"))
|
148 |
chatbot1 = gr.Chatbot(elem_id="chat_bot1").style(color_map=("green", "blue"))
|
149 |
with gr.Row(elem_id="prompt_row"):
|
150 |
-
|
151 |
prompt_input = gr.Textbox(lines=2, label="Input text",show_label=True)
|
152 |
chat_history = gr.Textbox(lines=4, label="prompt", visible=False)
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
submit_btn = gr.Button(value = "Submit",elem_id="submit-btn").style(
|
163 |
margin=True,
|
164 |
rounded=(True, True, True, True),
|
|
|
19 |
device=device,
|
20 |
)
|
21 |
|
22 |
+
all_special_ids = whisper_model.tokenizer.all_special_ids
|
23 |
+
transcribe_token_id = all_special_ids[-5]
|
24 |
+
translate_token_id = all_special_ids[-6]
|
25 |
+
|
26 |
+
def transcribe(audio):
|
27 |
+
task = "translate"
|
28 |
+
whisper_model.model.config.forced_decoder_ids = [[2, transcribe_token_id if task=="transcribe" else translate_token_id]]
|
29 |
+
text = whisper_model(audio)["text"]
|
30 |
+
return text
|
31 |
|
32 |
def get_response_from_chatbot(text):
|
33 |
try:
|
|
|
153 |
chatbot = gr.Chatbot(elem_id="chat_bot", visible=False).style(color_map=("green", "blue"))
|
154 |
chatbot1 = gr.Chatbot(elem_id="chat_bot1").style(color_map=("green", "blue"))
|
155 |
with gr.Row(elem_id="prompt_row"):
|
156 |
+
prompt_input_audio = gr.Audio(label = 'Record Audio Input',source="microphone",type="filepath")
|
157 |
prompt_input = gr.Textbox(lines=2, label="Input text",show_label=True)
|
158 |
chat_history = gr.Textbox(lines=4, label="prompt", visible=False)
|
159 |
+
transcribe_btn = gr.Button(value = "Transcribe").style(
|
160 |
+
margin=True,
|
161 |
+
rounded=(True, True, True, True),
|
162 |
+
width=100
|
163 |
+
)
|
164 |
+
transcribe_btn.click(fn=transcribe,
|
165 |
+
inputs=prompt_input_audio,
|
166 |
+
outputs=prompt_input
|
167 |
+
)
|
168 |
submit_btn = gr.Button(value = "Submit",elem_id="submit-btn").style(
|
169 |
margin=True,
|
170 |
rounded=(True, True, True, True),
|