File size: 5,216 Bytes
2971e95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5280a21
 
f1599f0
5280a21
34960d1
5280a21
2971e95
5280a21
4c92b32
2971e95
 
5280a21
2971e95
 
5280a21
 
2971e95
 
 
5280a21
2971e95
5280a21
2971e95
5280a21
 
2971e95
 
 
 
 
 
5280a21
2971e95
5280a21
 
2971e95
5280a21
 
2971e95
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# import openai
# import gradio as gr
# import config



# openai.api_key = config.OPENAI_API_KEY

# messages = [
#     {"role": "system", "content":"You are an attachment and personality surveyor"}, 
#     {"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:  
# What is your romantic partner's name?
# How did you two meet?
# When did you know you wanted to be with this person?
# Can you describe your relationship for me?
# How serious is your relationship?
# Have you thought about having kids with your romantic partner?
# What kind of parent do you want to be?
# If they didn't elaborate on the reason why, ask them "Why"?
# How did your relationship with your mother and father impact your plans to have children?
# What was your relationship with your mother like as a kid?
# How has your relationship with your mother changed since you were a kid?
# What was your relationship with your father like as a kid?
# How has your relationship with your mother like as a kid?
# After asking these questions, you can bid them farewell and thank them for their time. Show a lot of gratitude here.
# """}
# ]


# def convert_audio_to_text(audio):
#     audio_file = open(audio, "rb")
#     transcript = openai.Audio.transcribe("whisper-1", audio_file)
#     return transcript

# def chatbot(input):
#     # if input_type == "audio":
#     #     input = convert_audio_to_text(input)
#     if input:
#         messages.append({"role": "user", "content": input})
#         chat = openai.ChatCompletion.create(
#             model="gpt-3.5-turbo", messages=messages
#         )
#         reply = chat.choices[0].message.content
#         messages.append({"role": "assistant", "content": reply})
#         return reply


# # Define the Gradio interfaces
# # text_interface = gr.Interface(fn=chatbot, inputs=gr.inputs.Textbox("Enter your message here"), outputs="text", title="Text Input")
# # audio_interface = gr.Interface(fn=chatbot, inputs=gr.inputs.Audio(source="microphone", type="numpy"), outputs="text", title="Audio Input")

# # inputs_text = gr.inputs.Textbox(lines=7, label="Chat with AI")
# # inputs_audio = gr.inputs.Audio(source="microphone", type="numpy")
# # outputs = gr.outputs.Textbox(label="Reply")

# # text_interface = gr.Interface(fn=chatbot, inputs=inputs_text, outputs=outputs, title="AttachmentBot",
# #              description="Let me survey you about your attachment with certain people in your life",
# #              theme="compact").launch(share=True)

# # audio_interface = gr.Interface(fn=chatbot, inputs=inputs_audio, outputs=outputs, title="AttachmentBot",
# #              description="Let me survey you about your attachment with certain people in your life",
# #              theme="compact").launch(share=True)
# # Create a tabbed interface
# # tabbed_interface = gr.TabbedInterface([text_interface, audio_interface])

# # Launch the interface
# # tabbed_interface.launch(share=True)

# inputs = gr.inputs.Textbox(lines=7, label="Chat with AttachmentBot")
# outputs = gr.outputs.Textbox(label="Reply")



# gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="AttachmentBot",
#              description="Let's learn more about the important relationships in your life. Type 'start' in the box below to begin.",
#              theme="compact").launch()



import openai
import gradio as gr
import config

openai.api_key = config.OPENAI_API_KEY

initial_messages = [
    {"role": "system", "content":"You are an attachment and personality surveyor"}, 
    {"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:  
Can you describe your relationship with your mother or a mother-like figure in your life?
Do you usually discuss your problems and concerns with your mother or a mother-like figure?

"""},
]

def chatbot(input):
    if not hasattr(chatbot, "messages"):
        chatbot.messages = initial_messages.copy()
    
    if input:
        chatbot.messages.append({"role": "user", "content": input})
        chat = openai.ChatCompletion.create(
            model="gpt-3.5-turbo", messages=chatbot.messages
        )
        reply = chat.choices[0].message.content
        chatbot.messages.append({"role": "assistant", "content": reply})
        
        conversation = ""
        for message in chatbot.messages[2:]:
            role = "You" if message["role"] == "user" else "AttachmentBot"
            conversation += f"{role}: {message['content']}\n"

        return conversation

inputs = gr.inputs.Textbox(lines=7, label="Chat with AttachmentBot")
outputs = gr.outputs.Textbox(label="Conversation")

gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="AttachmentBot",
             description="Let me survey you about your attachment with certain people in your life, to begin enter start",
             theme="compact").launch()