Spaces:
Sleeping
Sleeping
import gradio as gr | |
import openai, config, subprocess | |
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: | |
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 transcribe(audio): | |
global messages | |
audio_file = open(audio, "rb") | |
transcript = openai.Audio.transcribe("whisper-1", audio_file) | |
messages.append({"role": "user", "content": transcript["text"]}) | |
response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages) | |
system_message = response["choices"][0]["message"] | |
messages.append(system_message) | |
subprocess.call(["say", system_message['content']]) | |
chat_transcript = "" | |
for message in messages: | |
if message['role'] != 'system': | |
chat_transcript += message['role'] + ": " + message['content'] + "\n\n" | |
return chat_transcript | |
ui = gr.Interface(fn=transcribe, inputs=gr.Audio(source="microphone", type="filepath"), outputs="text").launch() | |
ui.launch() |