Spaces:
Sleeping
Sleeping
Commit
·
e803545
1
Parent(s):
89e845e
Upload chatbot copy 2.py
Browse files- chatbot copy 2.py +101 -0
chatbot copy 2.py
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
openai.api_key = "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"
|
8 |
+
|
9 |
+
messages = [
|
10 |
+
{"role": "system", "content":"You are an attachment and personality 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:
|
12 |
+
Can you describe your relationship with your mother or a mother-like figure in your life?
|
13 |
+
Do you usually discuss your problems and concerns with your mother or a mother-like figure?
|
14 |
+
How often do you talk things over with your mother or a mother-like figure?
|
15 |
+
Do you find it easy to depend on your mother or a mother-like figure?
|
16 |
+
Are you comfortable opening up to your mother or a mother-like figure?
|
17 |
+
Do you show your mother or a mother-like figure how you feel deep down?
|
18 |
+
Do you ever worry that your mother or a mother-like figure doesn't really care for you?
|
19 |
+
Are you afraid that your mother or a mother-like figure may abandon you?
|
20 |
+
Do you worry that your mother or a mother-like figure won't care about you as much as you care about them?
|
21 |
+
Can you describe your relationship with your father or a father-like figure in your life?
|
22 |
+
Do you usually discuss your problems and concerns with your father or a father-like figure?
|
23 |
+
How often do you talk things over with your father or a father-like figure?
|
24 |
+
Do you find it easy to depend on your father or a father-like figure?
|
25 |
+
Are you comfortable opening up to your father or a father-like figure?
|
26 |
+
Do you show your father or a father-like figure how you feel deep down?
|
27 |
+
Do you ever worry that your father or a father-like figure doesn't really care for you?
|
28 |
+
Are you afraid that your father or a father-like figure may abandon you?
|
29 |
+
Do you worry that your father or a father-like figure won't care about you as much as you care about them?
|
30 |
+
Can you describe your relationship with your dating or marital partner?
|
31 |
+
Do you usually turn to your dating or marital partner in times of need?
|
32 |
+
How often do you discuss your problems and concerns with your dating or marital partner?
|
33 |
+
Do you find it easy to depend on your dating or marital partner?
|
34 |
+
Are you comfortable opening up to your dating or marital partner?
|
35 |
+
Do you show your dating or marital partner how you feel deep down?
|
36 |
+
Do you ever worry that your dating or marital partner doesn't really care for you?
|
37 |
+
Are you afraid that your dating or marital partner may abandon you?
|
38 |
+
Do you worry that your dating or marital partner won't care about you as much as you care about them?
|
39 |
+
Can you describe your relationship with your best friend?
|
40 |
+
Do you usually turn to your best friend in times of need?
|
41 |
+
How often do you discuss your problems and concerns with your best friend?
|
42 |
+
Do you find it easy to depend on your best friend?
|
43 |
+
Are you comfortable opening up to your best friend?
|
44 |
+
Do you show your best friend how you feel deep down?
|
45 |
+
Do you ever worry that your best friend doesn't really care for you?
|
46 |
+
Are you afraid that your best friend may abandon you?
|
47 |
+
Do you worry that your best friend won't care about you as much as you care about them?
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
"""}
|
52 |
+
]
|
53 |
+
|
54 |
+
|
55 |
+
def convert_audio_to_text(audio):
|
56 |
+
audio_file = open(audio, "rb")
|
57 |
+
transcript = openai.Audio.transcribe("whisper-1", audio_file)
|
58 |
+
return transcript
|
59 |
+
|
60 |
+
def chatbot(input):
|
61 |
+
# if input_type == "audio":
|
62 |
+
# input = convert_audio_to_text(input)
|
63 |
+
if input:
|
64 |
+
messages.append({"role": "user", "content": input})
|
65 |
+
chat = openai.ChatCompletion.create(
|
66 |
+
model="gpt-3.5-turbo", messages=messages
|
67 |
+
)
|
68 |
+
reply = chat.choices[0].message.content
|
69 |
+
messages.append({"role": "assistant", "content": reply})
|
70 |
+
return reply
|
71 |
+
|
72 |
+
|
73 |
+
# Define the Gradio interfaces
|
74 |
+
# text_interface = gr.Interface(fn=chatbot, inputs=gr.inputs.Textbox("Enter your message here"), outputs="text", title="Text Input")
|
75 |
+
# audio_interface = gr.Interface(fn=chatbot, inputs=gr.inputs.Audio(source="microphone", type="numpy"), outputs="text", title="Audio Input")
|
76 |
+
|
77 |
+
# inputs_text = gr.inputs.Textbox(lines=7, label="Chat with AI")
|
78 |
+
# inputs_audio = gr.inputs.Audio(source="microphone", type="numpy")
|
79 |
+
# outputs = gr.outputs.Textbox(label="Reply")
|
80 |
+
|
81 |
+
# text_interface = gr.Interface(fn=chatbot, inputs=inputs_text, outputs=outputs, title="AttachmentBot",
|
82 |
+
# description="Let me survey you about your attachment with certain people in your life",
|
83 |
+
# theme="compact").launch(share=True)
|
84 |
+
|
85 |
+
# audio_interface = gr.Interface(fn=chatbot, inputs=inputs_audio, outputs=outputs, title="AttachmentBot",
|
86 |
+
# description="Let me survey you about your attachment with certain people in your life",
|
87 |
+
# theme="compact").launch(share=True)
|
88 |
+
# Create a tabbed interface
|
89 |
+
# tabbed_interface = gr.TabbedInterface([text_interface, audio_interface])
|
90 |
+
|
91 |
+
# Launch the interface
|
92 |
+
# tabbed_interface.launch(share=True)
|
93 |
+
|
94 |
+
inputs = gr.inputs.Textbox(lines=7, label="Chat with AttachmentBot")
|
95 |
+
outputs = gr.outputs.Textbox(label="Reply")
|
96 |
+
|
97 |
+
|
98 |
+
|
99 |
+
gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="AttachmentBot",
|
100 |
+
description="Let me survey you about your attachment with certain people in your life",
|
101 |
+
theme="compact").launch()
|