Spaces:
Runtime error
Runtime error
added app
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
import gradio as gr
|
3 |
+
import subprocess
|
4 |
+
openai.api_key = "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"
|
5 |
+
messages = [ { "role": "system", "content":"You are a helpful therapist. I am very concise and give short answers."} ]
|
6 |
+
|
7 |
+
def transcribe(audio):
|
8 |
+
global messages
|
9 |
+
audio_file = open(audio, "rb")
|
10 |
+
transcript = openai.Audio.transcribe("whisper-1", audio_file)
|
11 |
+
|
12 |
+
messages.append({"role": "user", "content": transcript["text"]})
|
13 |
+
response = openai.ChatCompletion.create(
|
14 |
+
model="gpt-3.5-turbo",
|
15 |
+
messages=messages
|
16 |
+
)
|
17 |
+
|
18 |
+
system_message = response["choices"][0]["message"]["content"]
|
19 |
+
|
20 |
+
messages.append({ "role": "assistant", "content": system_message })
|
21 |
+
|
22 |
+
chat_transcript = ""
|
23 |
+
for message in messages:
|
24 |
+
if message['role'] != 'system':
|
25 |
+
chat_transcript += message['role'] + ": " + message['content'] + "\n----------------------\n"
|
26 |
+
subprocess.call(["say", system_message])
|
27 |
+
return chat_transcript
|
28 |
+
|
29 |
+
|
30 |
+
ui = gr.Interface(fn=transcribe, inputs=gr.Audio(source="microphone", type="filepath"), outputs="text")
|
31 |
+
ui.launch(share=True)
|