Spaces:
Runtime error
Runtime error
Commit
·
0695967
1
Parent(s):
e638ce1
Update app.py
Browse files
app.py
CHANGED
@@ -9,11 +9,11 @@ import torch
|
|
9 |
session_token = os.environ.get('SessionToken')
|
10 |
# logger.info(f"session_token_: {session_token}")
|
11 |
|
12 |
-
whisper_model = whisper.load_model("
|
13 |
|
14 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
15 |
|
16 |
-
def
|
17 |
audio = whisper.load_audio(audio)
|
18 |
audio = whisper.pad_or_trim(audio)
|
19 |
|
@@ -39,11 +39,10 @@ def get_response_from_chatbot(text):
|
|
39 |
response = "Sorry, I'm tired. Please try again in some time"
|
40 |
return response
|
41 |
|
42 |
-
def chat(
|
43 |
out_chat = []
|
44 |
if chat_history != '':
|
45 |
out_chat = json.loads(chat_history)
|
46 |
-
message = translate(audio)
|
47 |
response = get_response_from_chatbot(message)
|
48 |
out_chat.append((message, response))
|
49 |
chat_history = json.dumps(out_chat)
|
@@ -152,12 +151,23 @@ with gr.Blocks(title='Talk to chatGPT') as demo:
|
|
152 |
chatbot1 = gr.Chatbot(elem_id="chat_bot1").style(color_map=("green", "blue"))
|
153 |
with gr.Row(elem_id="prompt_row"):
|
154 |
prompt_input_audio = gr.Audio(label = 'Record Audio Input',source="microphone",type="filepath")
|
|
|
155 |
chat_history = gr.Textbox(lines=4, label="prompt", visible=False)
|
156 |
-
|
157 |
margin=True,
|
158 |
rounded=(True, True, True, True),
|
159 |
width=100
|
160 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
submit_btn.click(fn=chat,
|
162 |
inputs=[prompt_input_audio, chat_history],
|
163 |
outputs=[chatbot, chat_history],
|
|
|
9 |
session_token = os.environ.get('SessionToken')
|
10 |
# logger.info(f"session_token_: {session_token}")
|
11 |
|
12 |
+
whisper_model = whisper.load_model("medium")
|
13 |
|
14 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
15 |
|
16 |
+
def transcribe(audio):
|
17 |
audio = whisper.load_audio(audio)
|
18 |
audio = whisper.pad_or_trim(audio)
|
19 |
|
|
|
39 |
response = "Sorry, I'm tired. Please try again in some time"
|
40 |
return response
|
41 |
|
42 |
+
def chat(message, chat_history):
|
43 |
out_chat = []
|
44 |
if chat_history != '':
|
45 |
out_chat = json.loads(chat_history)
|
|
|
46 |
response = get_response_from_chatbot(message)
|
47 |
out_chat.append((message, response))
|
48 |
chat_history = json.dumps(out_chat)
|
|
|
151 |
chatbot1 = gr.Chatbot(elem_id="chat_bot1").style(color_map=("green", "blue"))
|
152 |
with gr.Row(elem_id="prompt_row"):
|
153 |
prompt_input_audio = gr.Audio(label = 'Record Audio Input',source="microphone",type="filepath")
|
154 |
+
prompt_input = gr.Textbox(lines=2, label="Input text",show_label=True)
|
155 |
chat_history = gr.Textbox(lines=4, label="prompt", visible=False)
|
156 |
+
transcribe_btn = gr.Button(value = "Transcribe").style(
|
157 |
margin=True,
|
158 |
rounded=(True, True, True, True),
|
159 |
width=100
|
160 |
)
|
161 |
+
transcribe_btn_btn.click(fn=transcribe,
|
162 |
+
inputs=prompt_input_audio
|
163 |
+
outputs=prompt_input
|
164 |
+
)
|
165 |
+
submit_btn = gr.Button(value = "Submit",elem_id="submit-btn").style(
|
166 |
+
margin=True,
|
167 |
+
rounded=(True, True, True, True),
|
168 |
+
width=100
|
169 |
+
)
|
170 |
+
|
171 |
submit_btn.click(fn=chat,
|
172 |
inputs=[prompt_input_audio, chat_history],
|
173 |
outputs=[chatbot, chat_history],
|