whisperV2 / app.py
AbeerTrial's picture
Update app.py
1fb2cf7
import whisper
import gradio as gr
import openai # all the required libraries are installed & imported
model = whisper.load_model("medium")
openai.api_key='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'
from whisper.transcribe import LANGUAGES
def voice_chat(ERDoctor_Input):
messages = [
{"role": "system", "content": "You are a kind helpful assistant."},
]
user_message = model.transcribe(ERDoctor_Input)["text"]
#reply = user_message
messages.append(
{"role": "user", "content": user_message},
)
chat = openai.ChatCompletion.create(
model="gpt-3.5-turbo", messages=messages
)
reply = chat.choices[0].message.content
messages.append({"role": "assistant", "content": reply})
return(reply)
text_reply = gr.Textbox(label="ChatGPT Text")
gr.Interface(
title = 'Open AI Whisper Speech Recognition V2',
fn=voice_chat,
inputs=[
gr.Audio(source="microphone", type="filepath")
],
outputs=[
text_reply
], live = True,
flagging_options= ["Incorrect Response"]
).launch()