Spaces:
Runtime error
Runtime error
Commit
·
ff1d740
1
Parent(s):
5dd9606
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,36 +8,24 @@ import torch
|
|
| 8 |
|
| 9 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
model="openai/whisper-large-v2",
|
| 14 |
-
chunk_length_s=30,
|
| 15 |
-
device=device,
|
| 16 |
-
)
|
| 17 |
-
|
| 18 |
-
all_special_ids = whisper_model.tokenizer.all_special_ids
|
| 19 |
-
transcribe_token_id = all_special_ids[-5]
|
| 20 |
-
translate_token_id = all_special_ids[-6]
|
| 21 |
|
|
|
|
| 22 |
def translate_or_transcribe(audio, task):
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
return text
|
| 26 |
|
| 27 |
-
def get_response_from_chatbot(text):
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
response = resp['message']
|
| 31 |
-
# logger.info(f"response_: {response}")
|
| 32 |
-
except:
|
| 33 |
-
response = "Sorry, the chatGPT queue is full. Please try again in some time"
|
| 34 |
return response
|
| 35 |
|
| 36 |
def chat(message, chat_history):
|
| 37 |
out_chat = []
|
| 38 |
if chat_history != '':
|
| 39 |
out_chat = json.loads(chat_history)
|
| 40 |
-
response = get_response_from_chatbot(message)
|
| 41 |
out_chat.append((message, response))
|
| 42 |
chat_history = json.dumps(out_chat)
|
| 43 |
logger.info(f"out_chat_: {len(out_chat)}")
|
|
@@ -153,7 +141,7 @@ with gr.Blocks(title='Talk to chatGPT') as demo:
|
|
| 153 |
)
|
| 154 |
translate_btn = gr.Button("Check Whisper first ? 👍")
|
| 155 |
|
| 156 |
-
whisper_task = gr.Radio(["
|
| 157 |
with gr.Row(elem_id="prompt_row"):
|
| 158 |
prompt_input = gr.Textbox(lines=2, label="Input text",show_label=True)
|
| 159 |
chat_history = gr.Textbox(lines=4, label="prompt", visible=False)
|
|
|
|
| 8 |
|
| 9 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 10 |
|
| 11 |
+
whisper = gr.Interface.load(name="spaces/sanchit-gandhi/whisper-large-v2")
|
| 12 |
+
openai_chatgpt = gr.Interface.load(name="spaces/anzorq/chatgpt-demo")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
#input_message.submit([input_message, history], [input_message, chatbot, history])
|
| 15 |
def translate_or_transcribe(audio, task):
|
| 16 |
+
text_result = whisper(audio, None, task, fn_index=0)
|
| 17 |
+
return text_result
|
|
|
|
| 18 |
|
| 19 |
+
def get_response_from_chatbot(text, chat_history):
|
| 20 |
+
r = openai_chatgpt(message, chat_history)
|
| 21 |
+
response = "Sorry, the chatGPT queue is full. Please try again in some time"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
return response
|
| 23 |
|
| 24 |
def chat(message, chat_history):
|
| 25 |
out_chat = []
|
| 26 |
if chat_history != '':
|
| 27 |
out_chat = json.loads(chat_history)
|
| 28 |
+
response = get_response_from_chatbot(message, chat_history)
|
| 29 |
out_chat.append((message, response))
|
| 30 |
chat_history = json.dumps(out_chat)
|
| 31 |
logger.info(f"out_chat_: {len(out_chat)}")
|
|
|
|
| 141 |
)
|
| 142 |
translate_btn = gr.Button("Check Whisper first ? 👍")
|
| 143 |
|
| 144 |
+
whisper_task = gr.Radio(["translate", "transcribe"], value="transcribe", show_label=False)
|
| 145 |
with gr.Row(elem_id="prompt_row"):
|
| 146 |
prompt_input = gr.Textbox(lines=2, label="Input text",show_label=True)
|
| 147 |
chat_history = gr.Textbox(lines=4, label="prompt", visible=False)
|