Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ from gtts import gTTS
|
|
6 |
|
7 |
openai.api_key = os.environ["OPEN_AI_KEY"]
|
8 |
|
9 |
-
|
10 |
|
11 |
|
12 |
|
@@ -17,9 +17,9 @@ def transcribe(audio):
|
|
17 |
|
18 |
return transcript["text"]
|
19 |
|
20 |
-
def botResponse(user_input):
|
21 |
#global messages
|
22 |
-
messages =
|
23 |
|
24 |
messages.append({"role": "user", "content": user_input})
|
25 |
response = openai.ChatCompletion.create(
|
@@ -58,7 +58,7 @@ with gr.Blocks() as demo:
|
|
58 |
gpt_transcript = gr.Text(label="Chat Transcript")
|
59 |
gpt_voice = gr.Audio(label="Voice Response")
|
60 |
submit_btn.click(transcribe, inputs=user_audio, outputs=user_transcript)
|
61 |
-
user_transcript.change(botResponse, inputs=user_transcript, outputs=gpt_transcript)
|
62 |
gpt_transcript.change(giveVoice, inputs=gpt_transcript, outputs=gpt_voice)
|
63 |
|
64 |
|
|
|
6 |
|
7 |
openai.api_key = os.environ["OPEN_AI_KEY"]
|
8 |
|
9 |
+
messages = gr.State(value=[{"role": "system", "content": "You are a therapist. Respond in less than 5 sentences."}])
|
10 |
|
11 |
|
12 |
|
|
|
17 |
|
18 |
return transcript["text"]
|
19 |
|
20 |
+
def botResponse(user_input, msg_contents):
|
21 |
#global messages
|
22 |
+
messages = msg_contents
|
23 |
|
24 |
messages.append({"role": "user", "content": user_input})
|
25 |
response = openai.ChatCompletion.create(
|
|
|
58 |
gpt_transcript = gr.Text(label="Chat Transcript")
|
59 |
gpt_voice = gr.Audio(label="Voice Response")
|
60 |
submit_btn.click(transcribe, inputs=user_audio, outputs=user_transcript)
|
61 |
+
user_transcript.change(botResponse, inputs=[user_transcript, messages], outputs=gpt_transcript)
|
62 |
gpt_transcript.change(giveVoice, inputs=gpt_transcript, outputs=gpt_voice)
|
63 |
|
64 |
|