Spaces:
Sleeping
Sleeping
Commit
·
8939274
1
Parent(s):
42dbf45
Upload vocalAttachmentBot.py
Browse files- vocalAttachmentBot.py +73 -0
vocalAttachmentBot.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import openai, config, subprocess
|
| 3 |
+
openai.api_key = config.OPENAI_API_KEY
|
| 4 |
+
|
| 5 |
+
messages = [
|
| 6 |
+
{"role": "system", "content":"You are an attachment and personality surveyor"},
|
| 7 |
+
{"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:
|
| 8 |
+
Can you describe your relationship with your mother or a mother-like figure in your life?
|
| 9 |
+
Do you usually discuss your problems and concerns with your mother or a mother-like figure?
|
| 10 |
+
How often do you talk things over with your mother or a mother-like figure?
|
| 11 |
+
Do you find it easy to depend on your mother or a mother-like figure?
|
| 12 |
+
Are you comfortable opening up to your mother or a mother-like figure?
|
| 13 |
+
Do you show your mother or a mother-like figure how you feel deep down?
|
| 14 |
+
Do you ever worry that your mother or a mother-like figure doesn't really care for you?
|
| 15 |
+
Are you afraid that your mother or a mother-like figure may abandon you?
|
| 16 |
+
Do you worry that your mother or a mother-like figure won't care about you as much as you care about them?
|
| 17 |
+
Can you describe your relationship with your father or a father-like figure in your life?
|
| 18 |
+
Do you usually discuss your problems and concerns with your father or a father-like figure?
|
| 19 |
+
How often do you talk things over with your father or a father-like figure?
|
| 20 |
+
Do you find it easy to depend on your father or a father-like figure?
|
| 21 |
+
Are you comfortable opening up to your father or a father-like figure?
|
| 22 |
+
Do you show your father or a father-like figure how you feel deep down?
|
| 23 |
+
Do you ever worry that your father or a father-like figure doesn't really care for you?
|
| 24 |
+
Are you afraid that your father or a father-like figure may abandon you?
|
| 25 |
+
Do you worry that your father or a father-like figure won't care about you as much as you care about them?
|
| 26 |
+
Can you describe your relationship with your dating or marital partner?
|
| 27 |
+
Do you usually turn to your dating or marital partner in times of need?
|
| 28 |
+
How often do you discuss your problems and concerns with your dating or marital partner?
|
| 29 |
+
Do you find it easy to depend on your dating or marital partner?
|
| 30 |
+
Are you comfortable opening up to your dating or marital partner?
|
| 31 |
+
Do you show your dating or marital partner how you feel deep down?
|
| 32 |
+
Do you ever worry that your dating or marital partner doesn't really care for you?
|
| 33 |
+
Are you afraid that your dating or marital partner may abandon you?
|
| 34 |
+
Do you worry that your dating or marital partner won't care about you as much as you care about them?
|
| 35 |
+
Can you describe your relationship with your best friend?
|
| 36 |
+
Do you usually turn to your best friend in times of need?
|
| 37 |
+
How often do you discuss your problems and concerns with your best friend?
|
| 38 |
+
Do you find it easy to depend on your best friend?
|
| 39 |
+
Are you comfortable opening up to your best friend?
|
| 40 |
+
Do you show your best friend how you feel deep down?
|
| 41 |
+
Do you ever worry that your best friend doesn't really care for you?
|
| 42 |
+
Are you afraid that your best friend may abandon you?
|
| 43 |
+
Do you worry that your best friend won't care about you as much as you care about them?
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
"""}
|
| 48 |
+
]
|
| 49 |
+
|
| 50 |
+
def transcribe(audio):
|
| 51 |
+
global messages
|
| 52 |
+
|
| 53 |
+
audio_file = open(audio, "rb")
|
| 54 |
+
transcript = openai.Audio.transcribe("whisper-1", audio_file)
|
| 55 |
+
|
| 56 |
+
messages.append({"role": "user", "content": transcript["text"]})
|
| 57 |
+
|
| 58 |
+
response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages)
|
| 59 |
+
|
| 60 |
+
system_message = response["choices"][0]["message"]
|
| 61 |
+
messages.append(system_message)
|
| 62 |
+
|
| 63 |
+
subprocess.call(["say", system_message['content']])
|
| 64 |
+
|
| 65 |
+
chat_transcript = ""
|
| 66 |
+
for message in messages:
|
| 67 |
+
if message['role'] != 'system':
|
| 68 |
+
chat_transcript += message['role'] + ": " + message['content'] + "\n\n"
|
| 69 |
+
|
| 70 |
+
return chat_transcript
|
| 71 |
+
|
| 72 |
+
ui = gr.Interface(fn=transcribe, inputs=gr.Audio(source="microphone", type="filepath"), outputs="text").launch()
|
| 73 |
+
ui.launch()
|