Spaces:
Sleeping
Sleeping
AjithKSenthil
commited on
Commit
•
85570bf
1
Parent(s):
f54de8f
Upload 2 files
Browse files- chatbot.py +43 -0
- config.py +3 -0
chatbot.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
import openai
|
4 |
+
import gradio as gr
|
5 |
+
import config
|
6 |
+
|
7 |
+
openai.api_key = config.OPENAI_API_KEY
|
8 |
+
|
9 |
+
# NOTE: You can change the system prompts to assign a role and specify how you want the chatbot to interact with your participants
|
10 |
+
initial_messages = [
|
11 |
+
{"role": "system", "content":"You are an attachment and close relationship research surveyor"},
|
12 |
+
{"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:
|
13 |
+
Can you describe your relationship with your mother or a mother-like figure in your life?
|
14 |
+
Do you usually discuss your problems and concerns with your mother or a mother-like figure?
|
15 |
+
|
16 |
+
"""},
|
17 |
+
]
|
18 |
+
|
19 |
+
def chatbot(input):
|
20 |
+
if not hasattr(chatbot, "messages"):
|
21 |
+
chatbot.messages = initial_messages.copy()
|
22 |
+
|
23 |
+
if input:
|
24 |
+
chatbot.messages.append({"role": "user", "content": input})
|
25 |
+
chat = openai.ChatCompletion.create(
|
26 |
+
model="gpt-3.5-turbo-0125", messages=chatbot.messages
|
27 |
+
)
|
28 |
+
reply = chat.choices[0].message.content
|
29 |
+
chatbot.messages.append({"role": "assistant", "content": reply})
|
30 |
+
|
31 |
+
conversation = ""
|
32 |
+
for message in chatbot.messages[2:]:
|
33 |
+
role = "You" if message["role"] == "user" else "AttachmentBot"
|
34 |
+
conversation += f"{role}: {message['content']}\n"
|
35 |
+
|
36 |
+
return conversation
|
37 |
+
|
38 |
+
inputs = gr.inputs.Textbox(lines=7, label="Chat with AttachmentBot")
|
39 |
+
outputs = gr.outputs.Textbox(label="Conversation")
|
40 |
+
|
41 |
+
gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="AttachmentBot",
|
42 |
+
description="Let me survey you about your attachment with certain people in your life, to begin enter start",
|
43 |
+
theme="compact").launch()
|
config.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
|