AjithKSenthil's picture
Upload chatbot.py
db8f25f
raw
history blame
No virus
8.17 kB
import openai
import gradio as gr
openai.api_key = "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"
messages = [
{"role": "system", "content":"You are an attachment and personality surveyor"},
{"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:
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.
-----------------------------------------------------------------------------
Please answer the following questions about your mother or a mother-like figure
-----------------------------------------------------------------------------
1. It helps to turn to this person in times of need.
strongly disagree 1 2 3 4 5 6 7 strongly agree
2. I usually discuss my problems and concerns with this person.
strongly disagree 1 2 3 4 5 6 7 strongly agree
3. I talk things over with this person.
strongly disagree 1 2 3 4 5 6 7 strongly agree
4. I find it easy to depend on this person.
strongly disagree 1 2 3 4 5 6 7 strongly agree
5. I don't feel comfortable opening up to this person.
strongly disagree 1 2 3 4 5 6 7 strongly agree
6. I prefer not to show this person how I feel deep down.
strongly disagree 1 2 3 4 5 6 7 strongly agree
7. I often worry that this person doesn't really care for me.
strongly disagree 1 2 3 4 5 6 7 strongly agree
8. I'm afraid that this person may abandon me.
strongly disagree 1 2 3 4 5 6 7 strongly agree
9. I worry that this person won't care about me as much as I care about him or her.
strongly disagree 1 2 3 4 5 6 7 strongly agree
-----------------------------------------------------------------------------
Please answer the following questions about your father or a father-like figure
-----------------------------------------------------------------------------
1. It helps to turn to this person in times of need.
strongly disagree 1 2 3 4 5 6 7 strongly agree
2. I usually discuss my problems and concerns with this person.
strongly disagree 1 2 3 4 5 6 7 strongly agree
3. I talk things over with this person.
strongly disagree 1 2 3 4 5 6 7 strongly agree
4. I find it easy to depend on this person.
strongly disagree 1 2 3 4 5 6 7 strongly agree
5. I don't feel comfortable opening up to this person.
strongly disagree 1 2 3 4 5 6 7 strongly agree
6. I prefer not to show this person how I feel deep down.
strongly disagree 1 2 3 4 5 6 7 strongly agree
7. I often worry that this person doesn't really care for me.
strongly disagree 1 2 3 4 5 6 7 strongly agree
8. I'm afraid that this person may abandon me.
strongly disagree 1 2 3 4 5 6 7 strongly agree
9. I worry that this person won't care about me as much as I care about him or her.
strongly disagree 1 2 3 4 5 6 7 strongly agree
-----------------------------------------------------------------------------
Please answer the following questions about your dating or marital partner.
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.
-----------------------------------------------------------------------------
1. It helps to turn to this person in times of need.
strongly disagree 1 2 3 4 5 6 7 strongly agree
2. I usually discuss my problems and concerns with this person.
strongly disagree 1 2 3 4 5 6 7 strongly agree
3. I talk things over with this person.
strongly disagree 1 2 3 4 5 6 7 strongly agree
4. I find it easy to depend on this person.
strongly disagree 1 2 3 4 5 6 7 strongly agree
5. I don't feel comfortable opening up to this person.
strongly disagree 1 2 3 4 5 6 7 strongly agree
6. I prefer not to show this person how I feel deep down.
strongly disagree 1 2 3 4 5 6 7 strongly agree
7. I often worry that this person doesn't really care for me.
strongly disagree 1 2 3 4 5 6 7 strongly agree
8. I'm afraid that this person may abandon me.
strongly disagree 1 2 3 4 5 6 7 strongly agree
9. I worry that this person won't care about me as much as I care about him or her.
strongly disagree 1 2 3 4 5 6 7 strongly agree
-----------------------------------------------------------------------------
Please answer the following questions about your best friend
-----------------------------------------------------------------------------
1. It helps to turn to this person in times of need.
strongly disagree 1 2 3 4 5 6 7 strongly agree
2. I usually discuss my problems and concerns with this person.
strongly disagree 1 2 3 4 5 6 7 strongly agree
3. I talk things over with this person.
strongly disagree 1 2 3 4 5 6 7 strongly agree
4. I find it easy to depend on this person.
strongly disagree 1 2 3 4 5 6 7 strongly agree
5. I don't feel comfortable opening up to this person.
strongly disagree 1 2 3 4 5 6 7 strongly agree
6. I prefer not to show this person how I feel deep down.
strongly disagree 1 2 3 4 5 6 7 strongly agree
7. I often worry that this person doesn't really care for me.
strongly disagree 1 2 3 4 5 6 7 strongly agree
8. I'm afraid that this person may abandon me.
strongly disagree 1 2 3 4 5 6 7 strongly agree
9. I worry that this person won't care about me as much as I care about him or her.
strongly disagree 1 2 3 4 5 6 7 strongly agree
"""}
]
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 me survey you about your attachment with certain people in your life",
theme="compact").launch()