Spaces:
Sleeping
Sleeping
Update app.py
#2
by
hwberry2
- opened
app.py
CHANGED
|
@@ -14,7 +14,7 @@ openai.api_key = os.environ["OPEN_AI_KEY"]
|
|
| 14 |
messages = [{"role": "system", "content": "You are a therapist. Respond in less than 5 sentences."}]
|
| 15 |
|
| 16 |
|
| 17 |
-
def transcribe(audio
|
| 18 |
stringIn = test
|
| 19 |
|
| 20 |
audio_file = open(audio, "rb")
|
|
@@ -28,21 +28,22 @@ def transcribe(audio, test):
|
|
| 28 |
#for message in msg_contents:
|
| 29 |
# if (message["role"] != "system"):
|
| 30 |
# chat_transcript += message["role"] + ": " + message["content"] + "\n\n"
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
def botResponse(chat_log, msg_contents):
|
| 35 |
response = openai.ChatCompletion.create(
|
| 36 |
model="gpt-3.5-turbo",
|
| 37 |
-
messages=
|
| 38 |
|
| 39 |
system_message = response["choices"][0]["message"]["content"]
|
| 40 |
-
msg_contents.append({"role": "assistant", "content": system_message})
|
| 41 |
|
| 42 |
-
chat_transcript = chat_log
|
| 43 |
-
for message in msg_contents:
|
| 44 |
-
|
| 45 |
-
|
| 46 |
|
| 47 |
return system_message
|
| 48 |
|
|
@@ -73,7 +74,7 @@ with gr.Blocks() as demo:
|
|
| 73 |
gpt_transcript = gr.Text(label="Generate Transcript")
|
| 74 |
gpt_transcript2 = gr.Text(label="Bot Response")
|
| 75 |
gpt_response = gr.Audio(label="Voice Response")
|
| 76 |
-
submit_btn.click(transcribe, inputs=
|
| 77 |
|
| 78 |
|
| 79 |
|
|
|
|
| 14 |
messages = [{"role": "system", "content": "You are a therapist. Respond in less than 5 sentences."}]
|
| 15 |
|
| 16 |
|
| 17 |
+
def transcribe(audio):
|
| 18 |
stringIn = test
|
| 19 |
|
| 20 |
audio_file = open(audio, "rb")
|
|
|
|
| 28 |
#for message in msg_contents:
|
| 29 |
# if (message["role"] != "system"):
|
| 30 |
# chat_transcript += message["role"] + ": " + message["content"] + "\n\n"
|
| 31 |
+
system_response = botResponse(transcript)
|
| 32 |
+
|
| 33 |
+
return system_response
|
| 34 |
|
| 35 |
+
def botResponse(user_input):
|
|
|
|
|
|
|
| 36 |
response = openai.ChatCompletion.create(
|
| 37 |
model="gpt-3.5-turbo",
|
| 38 |
+
messages=user_input)
|
| 39 |
|
| 40 |
system_message = response["choices"][0]["message"]["content"]
|
| 41 |
+
#msg_contents.append({"role": "assistant", "content": system_message})
|
| 42 |
|
| 43 |
+
#chat_transcript = chat_log
|
| 44 |
+
#for message in msg_contents:
|
| 45 |
+
# if (message["role"] != "system"):
|
| 46 |
+
# chat_transcript += message["role"] + ": " + message["content"] + "\n\n"
|
| 47 |
|
| 48 |
return system_message
|
| 49 |
|
|
|
|
| 74 |
gpt_transcript = gr.Text(label="Generate Transcript")
|
| 75 |
gpt_transcript2 = gr.Text(label="Bot Response")
|
| 76 |
gpt_response = gr.Audio(label="Voice Response")
|
| 77 |
+
submit_btn.click(transcribe, inputs=user_audio, outputs=gpt_transcript)
|
| 78 |
|
| 79 |
|
| 80 |
|