Spaces:
Runtime error
Runtime error
Commit
·
057830c
1
Parent(s):
c7443d0
Init whisper
Browse files
app.py
CHANGED
@@ -9,15 +9,29 @@ 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 get_response_from_chatbot(
|
17 |
try:
|
18 |
-
print("Testing indentation")
|
19 |
api = ChatGPT(session_token)
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
api.refresh_auth()
|
22 |
api.reset_conversation()
|
23 |
response = resp['message']
|
@@ -137,7 +151,7 @@ with gr.Blocks(title='Talk to chatGPT') as demo:
|
|
137 |
chatbot = gr.Chatbot(elem_id="chat_bot", visible=False).style(color_map=("green", "blue"))
|
138 |
chatbot1 = gr.Chatbot(elem_id="chat_bot1").style(color_map=("green", "blue"))
|
139 |
with gr.Row(elem_id="prompt_row"):
|
140 |
-
|
141 |
chat_history = gr.Textbox(lines=4, label="prompt", visible=False)
|
142 |
submit_btn = gr.Button(value = "submit",elem_id="submit-btn").style(
|
143 |
margin=True,
|
@@ -145,7 +159,7 @@ with gr.Blocks(title='Talk to chatGPT') as demo:
|
|
145 |
width=100
|
146 |
)
|
147 |
submit_btn.click(fn=chat,
|
148 |
-
inputs=[
|
149 |
outputs=[chatbot, chat_history],
|
150 |
)
|
151 |
|
|
|
9 |
session_token = os.environ.get('SessionToken')
|
10 |
# logger.info(f"session_token_: {session_token}")
|
11 |
|
12 |
+
whisper_model = whisper.load_model("base")
|
13 |
|
14 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
15 |
|
16 |
+
def get_response_from_chatbot(audio):
|
17 |
try:
|
|
|
18 |
api = ChatGPT(session_token)
|
19 |
+
audio = whisper.load_audio(audio)
|
20 |
+
audio = whisper.pad_or_trim(audio)
|
21 |
+
|
22 |
+
mel = whisper.log_mel_spectrogram(audio).to(whisper_model.device)
|
23 |
+
|
24 |
+
_, probs = whisper_model.detect_language(mel)
|
25 |
+
translate_options = whisper.DecodingOptions(task="translate", fp16 = False)
|
26 |
+
|
27 |
+
translation = whisper.decode(whisper_model, mel, translate_options)
|
28 |
+
|
29 |
+
print("Language Spoken: " + transcription.language)
|
30 |
+
|
31 |
+
print("Translated: " + translation.text)
|
32 |
+
|
33 |
+
|
34 |
+
resp = api.send_message(translation.text)
|
35 |
api.refresh_auth()
|
36 |
api.reset_conversation()
|
37 |
response = resp['message']
|
|
|
151 |
chatbot = gr.Chatbot(elem_id="chat_bot", visible=False).style(color_map=("green", "blue"))
|
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 = audio_input_r = gr.Audio(label = 'Record Audio Input',source="microphone",type="filepath")
|
155 |
chat_history = gr.Textbox(lines=4, label="prompt", visible=False)
|
156 |
submit_btn = gr.Button(value = "submit",elem_id="submit-btn").style(
|
157 |
margin=True,
|
|
|
159 |
width=100
|
160 |
)
|
161 |
submit_btn.click(fn=chat,
|
162 |
+
inputs=[prompt_input_audio, chat_history],
|
163 |
outputs=[chatbot, chat_history],
|
164 |
)
|
165 |
|