Spaces:
Sleeping
Sleeping
Update chatbot.py
Browse files- chatbot.py +7 -6
chatbot.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
import openai
|
| 2 |
import gradio as gr
|
| 3 |
-
import
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
initial_messages = [
|
| 9 |
{"role": "system", "content": "You are an attachment and close relationship research surveyor"},
|
| 10 |
{"role": "user", "content": """ask me each question from this questionnaire and rewrite it as an open ended question and wait for each response. Empathize with me and regularly ask for clarification why I answered with a certain response. Here is the questionnaire:
|
|
@@ -19,11 +20,11 @@ def chatbot(input):
|
|
| 19 |
|
| 20 |
if input:
|
| 21 |
chatbot.messages.append({"role": "user", "content": input})
|
| 22 |
-
|
| 23 |
model="gpt-3.5-turbo",
|
| 24 |
messages=chatbot.messages
|
| 25 |
)
|
| 26 |
-
reply =
|
| 27 |
chatbot.messages.append({"role": "assistant", "content": reply})
|
| 28 |
|
| 29 |
conversation = ""
|
|
@@ -41,5 +42,5 @@ gr.Interface(
|
|
| 41 |
inputs=inputs,
|
| 42 |
outputs=outputs,
|
| 43 |
title="AttachmentBot",
|
| 44 |
-
description="Let me survey you about your attachment with certain people in your life
|
| 45 |
).launch()
|
|
|
|
| 1 |
import openai
|
| 2 |
import gradio as gr
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
# Set OpenAI API key from environment variable
|
| 6 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 7 |
|
| 8 |
+
# Initial system messages for the chatbot
|
| 9 |
initial_messages = [
|
| 10 |
{"role": "system", "content": "You are an attachment and close relationship research surveyor"},
|
| 11 |
{"role": "user", "content": """ask me each question from this questionnaire and rewrite it as an open ended question and wait for each response. Empathize with me and regularly ask for clarification why I answered with a certain response. Here is the questionnaire:
|
|
|
|
| 20 |
|
| 21 |
if input:
|
| 22 |
chatbot.messages.append({"role": "user", "content": input})
|
| 23 |
+
response = openai.ChatCompletion.create(
|
| 24 |
model="gpt-3.5-turbo",
|
| 25 |
messages=chatbot.messages
|
| 26 |
)
|
| 27 |
+
reply = response.choices[0].message["content"]
|
| 28 |
chatbot.messages.append({"role": "assistant", "content": reply})
|
| 29 |
|
| 30 |
conversation = ""
|
|
|
|
| 42 |
inputs=inputs,
|
| 43 |
outputs=outputs,
|
| 44 |
title="AttachmentBot",
|
| 45 |
+
description="Let me survey you about your attachment with certain people in your life. To begin, enter 'start'."
|
| 46 |
).launch()
|