Spaces:
Sleeping
Sleeping
import openai | |
import gradio as gr | |
# openai.api_key = "your openAI api key here" or | |
openai.api_key = "your openAI api key here" | |
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? | |
How often do you talk things over with your mother or a mother-like figure? | |
Do you find it easy to depend on your mother or a mother-like figure? | |
Are you comfortable opening up to your mother or a mother-like figure? | |
Do you show your mother or a mother-like figure how you feel deep down? | |
Do you ever worry that your mother or a mother-like figure doesn't really care for you? | |
Are you afraid that your mother or a mother-like figure may abandon you? | |
Do you worry that your mother or a mother-like figure won't care about you as much as you care about them? | |
Can you describe your relationship with your father or a father-like figure in your life? | |
Do you usually discuss your problems and concerns with your father or a father-like figure? | |
How often do you talk things over with your father or a father-like figure? | |
Do you find it easy to depend on your father or a father-like figure? | |
Are you comfortable opening up to your father or a father-like figure? | |
Do you show your father or a father-like figure how you feel deep down? | |
Do you ever worry that your father or a father-like figure doesn't really care for you? | |
Are you afraid that your father or a father-like figure may abandon you? | |
Do you worry that your father or a father-like figure won't care about you as much as you care about them? | |
Can you describe your relationship with your dating or marital partner? | |
Do you usually turn to your dating or marital partner in times of need? | |
How often do you discuss your problems and concerns with your dating or marital partner? | |
Do you find it easy to depend on your dating or marital partner? | |
Are you comfortable opening up to your dating or marital partner? | |
Do you show your dating or marital partner how you feel deep down? | |
Do you ever worry that your dating or marital partner doesn't really care for you? | |
Are you afraid that your dating or marital partner may abandon you? | |
Do you worry that your dating or marital partner won't care about you as much as you care about them? | |
Can you describe your relationship with your best friend? | |
Do you usually turn to your best friend in times of need? | |
How often do you discuss your problems and concerns with your best friend? | |
Do you find it easy to depend on your best friend? | |
Are you comfortable opening up to your best friend? | |
Do you show your best friend how you feel deep down? | |
Do you ever worry that your best friend doesn't really care for you? | |
Are you afraid that your best friend may abandon you? | |
Do you worry that your best friend won't care about you as much as you care about them? | |
"""} | |
] | |
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() |