AjithKSenthil commited on
Commit
5280a21
1 Parent(s): 0c62e77

Upload 3 files

Browse files
Files changed (3) hide show
  1. chatbot.py +231 -0
  2. config.py +1 -0
  3. requirements.txt +2 -0
chatbot.py ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 one question at a time surveying for each response. After every few responses, ask for clarification why I answered with a certain level of attachment to that person. Here is the questionnaire:
12
+ This questionnaire is designed to assess the way in which you mentally represent important people in your life. Please indicate the extent to which you agree or disagree with each statement by responding with a number for each item.
13
+
14
+ -----------------------------------------------------------------------------
15
+ Please answer the following questions about your mother or a mother-like figure
16
+ -----------------------------------------------------------------------------
17
+
18
+ 1. It helps to turn to this person in times of need.
19
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
20
+
21
+
22
+ 2. I usually discuss my problems and concerns with this person.
23
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
24
+
25
+
26
+ 3. I talk things over with this person.
27
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
28
+
29
+
30
+ 4. I find it easy to depend on this person.
31
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
32
+
33
+
34
+ 5. I don't feel comfortable opening up to this person.
35
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
36
+
37
+
38
+ 6. I prefer not to show this person how I feel deep down.
39
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
40
+
41
+
42
+ 7. I often worry that this person doesn't really care for me.
43
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
44
+
45
+
46
+ 8. I'm afraid that this person may abandon me.
47
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
48
+
49
+
50
+ 9. I worry that this person won't care about me as much as I care about him or her.
51
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
52
+
53
+
54
+ -----------------------------------------------------------------------------
55
+ Please answer the following questions about your father or a father-like figure
56
+ -----------------------------------------------------------------------------
57
+
58
+ 1. It helps to turn to this person in times of need.
59
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
60
+
61
+
62
+ 2. I usually discuss my problems and concerns with this person.
63
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
64
+
65
+
66
+ 3. I talk things over with this person.
67
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
68
+
69
+
70
+ 4. I find it easy to depend on this person.
71
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
72
+
73
+
74
+ 5. I don't feel comfortable opening up to this person.
75
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
76
+
77
+
78
+ 6. I prefer not to show this person how I feel deep down.
79
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
80
+
81
+
82
+ 7. I often worry that this person doesn't really care for me.
83
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
84
+
85
+
86
+ 8. I'm afraid that this person may abandon me.
87
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
88
+
89
+
90
+ 9. I worry that this person won't care about me as much as I care about him or her.
91
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
92
+
93
+
94
+ -----------------------------------------------------------------------------
95
+ Please answer the following questions about your dating or marital partner.
96
+
97
+ Note: If you are not currently in a dating or marital relationship with someone, answer these questions with respect to a former partner or a relationship that you would like to have with someone.
98
+ -----------------------------------------------------------------------------
99
+
100
+ 1. It helps to turn to this person in times of need.
101
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
102
+
103
+
104
+ 2. I usually discuss my problems and concerns with this person.
105
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
106
+
107
+
108
+ 3. I talk things over with this person.
109
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
110
+
111
+
112
+ 4. I find it easy to depend on this person.
113
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
114
+
115
+
116
+ 5. I don't feel comfortable opening up to this person.
117
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
118
+
119
+
120
+ 6. I prefer not to show this person how I feel deep down.
121
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
122
+
123
+
124
+ 7. I often worry that this person doesn't really care for me.
125
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
126
+
127
+
128
+ 8. I'm afraid that this person may abandon me.
129
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
130
+
131
+
132
+ 9. I worry that this person won't care about me as much as I care about him or her.
133
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
134
+
135
+
136
+ -----------------------------------------------------------------------------
137
+ Please answer the following questions about your best friend
138
+
139
+ -----------------------------------------------------------------------------
140
+
141
+ 1. It helps to turn to this person in times of need.
142
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
143
+
144
+
145
+ 2. I usually discuss my problems and concerns with this person.
146
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
147
+
148
+
149
+ 3. I talk things over with this person.
150
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
151
+
152
+
153
+ 4. I find it easy to depend on this person.
154
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
155
+
156
+
157
+ 5. I don't feel comfortable opening up to this person.
158
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
159
+
160
+
161
+ 6. I prefer not to show this person how I feel deep down.
162
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
163
+
164
+
165
+ 7. I often worry that this person doesn't really care for me.
166
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
167
+
168
+
169
+ 8. I'm afraid that this person may abandon me.
170
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
171
+
172
+
173
+ 9. I worry that this person won't care about me as much as I care about him or her.
174
+ strongly disagree 1 2 3 4 5 6 7 strongly agree
175
+
176
+
177
+
178
+
179
+
180
+
181
+ """}
182
+ ]
183
+
184
+
185
+ def convert_audio_to_text(audio):
186
+ audio_file = open(audio, "rb")
187
+ transcript = openai.Audio.transcribe("whisper-1", audio_file)
188
+ return transcript
189
+
190
+ def chatbot(input):
191
+ # if input_type == "audio":
192
+ # input = convert_audio_to_text(input)
193
+ if input:
194
+ messages.append({"role": "user", "content": input})
195
+ chat = openai.ChatCompletion.create(
196
+ model="gpt-3.5-turbo", messages=messages
197
+ )
198
+ reply = chat.choices[0].message.content
199
+ messages.append({"role": "assistant", "content": reply})
200
+ return reply
201
+
202
+
203
+ # Define the Gradio interfaces
204
+ # text_interface = gr.Interface(fn=chatbot, inputs=gr.inputs.Textbox("Enter your message here"), outputs="text", title="Text Input")
205
+ # audio_interface = gr.Interface(fn=chatbot, inputs=gr.inputs.Audio(source="microphone", type="numpy"), outputs="text", title="Audio Input")
206
+
207
+ # inputs_text = gr.inputs.Textbox(lines=7, label="Chat with AI")
208
+ # inputs_audio = gr.inputs.Audio(source="microphone", type="numpy")
209
+ # outputs = gr.outputs.Textbox(label="Reply")
210
+
211
+ # text_interface = gr.Interface(fn=chatbot, inputs=inputs_text, outputs=outputs, title="AttachmentBot",
212
+ # description="Let me survey you about your attachment with certain people in your life",
213
+ # theme="compact").launch(share=True)
214
+
215
+ # audio_interface = gr.Interface(fn=chatbot, inputs=inputs_audio, outputs=outputs, title="AttachmentBot",
216
+ # description="Let me survey you about your attachment with certain people in your life",
217
+ # theme="compact").launch(share=True)
218
+ # Create a tabbed interface
219
+ # tabbed_interface = gr.TabbedInterface([text_interface, audio_interface])
220
+
221
+ # Launch the interface
222
+ # tabbed_interface.launch(share=True)
223
+
224
+ inputs = gr.inputs.Textbox(lines=7, label="Chat with AttachmentBot")
225
+ outputs = gr.outputs.Textbox(label="Reply")
226
+
227
+
228
+
229
+ gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="AttachmentBot",
230
+ description="Let me survey you about your attachment with certain people in your life",
231
+ theme="compact").launch(share=True)
config.py ADDED
@@ -0,0 +1 @@
 
 
1
+ OPENAI_API_KEY = "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"
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ openai
2
+ gradio