kotrotsos's picture
fixed shared state
05471ce
import openai
import gradio as gr
import os
openai.api_key = os.environ.get("openai_key")
def transcribe(audio):
messages = [ { "role": "system", "content":"You are a helpful therapist. I am very concise and give short answers."} ]
system_message = ""
audio_file = open(audio, "rb")
transcript = openai.Audio.transcribe("whisper-1", audio_file)
messages.append({"role": "user", "content": transcript["text"]})
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages
)
system_message = response["choices"][0]["message"]["content"]
messages.append({ "role": "assistant", "content": system_message })
chat_transcript = ""
for message in messages:
if message['role'] != 'system':
chat_transcript += message['role'] + ": " + message['content'] + "\n----------------------\n"
# subprocess.call(["say", system_message])
return chat_transcript
ui = gr.Interface(fn=transcribe, inputs=gr.Audio(source="microphone", type="filepath"), outputs="text")
ui.launch()