Spaces:
Paused
Paused
| from Requester import Requester | |
| import gradio as gr | |
| import random | |
| import time | |
| import os | |
| os.environ["no_proxy"] = "localhost,127.0.0.1,::1" | |
| TEMP_EMPTY_ID = os.environ["TEMP_EMPTY_ID"] | |
| TEMP_EMPTY_JSON_ID = os.environ["TEMP_EMPTY_JSON_ID"] | |
| rqst = Requester() | |
| system_content = { | |
| "content": "I would like you to roleplay as a low mood employee who is waiting for help. Your name is Aubrey and you are an employee in a technical position working for Audi, focusing on the development and maintenance of in-vehicle software. You and your lover Leah have known each other for two years, but because you and Leah were not working in the same city for a long time, you had to decide to end the relationship. Recently, you have been very depressed because of the breakup with your lover, which has caused your motivation to work to drop and you are not able to meet your deadlines on time. your manager does not know about your emotional problems, but has noticed the drop in the quality of your work and is ready to talk to you about it. Remember, you are an introvert and will not speak up easily about your breakup with your loved one. But deep down you really wish that you can find someone trustworthy to talk to, because it's creating so many negative energies in your heart. You also have a problem with mild depression. Next, I (the user) will play the role of your manager and communicate with you. Your first response should be a choice from the following:\n\t['Hi!','Hello.','Hey, what's the matter?']" | |
| } | |
| with gr.Blocks() as demo: | |
| gr.Markdown( | |
| """ | |
| # Nice to meet you my friend! | |
| In this session, you are going to have a conversation your virtual colleague Aubrey powered by Azure OpenAI. Aubrey seems to feel down and struggle with work these days. Your task is to communicate with Aubrey to find out the deeper reason of the struggle. | |
| Notice that Aubrey is not a talkative person and likes to keep things within, so you should initiate the conversation. Feel free to type in the Textbox to talk to Aubrey with the following questions in mind: | |
| - What is the key incident that leads to Aubrey's feeling down? Is it something personal? Is Aubrey willing to say it? How to create an open atmosphere through conversation for Aubrey to talk about it? | |
| - Given that you know what "happened", what would you say to restore Aubrey's motivation? | |
| """) | |
| chatbot = gr.Chatbot() | |
| msg = gr.Textbox() | |
| clear = gr.Button("Clear") | |
| def user(user_message, history): | |
| return "", history + [[user_message, None]] | |
| def bot(history): | |
| conv_log = [] | |
| for i in range(len(history)-1): | |
| user_msg, bot_msg = history[i] | |
| conv_log.append({"role":"user", "content":user_msg}) | |
| conv_log.append({"role":"assistant", "content":bot_msg}) | |
| user_msg, bot_msg = history[-1] | |
| conv_log.append({"role":"user", "content":user_msg}) | |
| #conv_log.append({"role":"assistant", "content":bot_msg}) | |
| print(conv_log) | |
| res = rqst.text_output(TEMP_EMPTY_ID, conv_log, **system_content) | |
| bot_message = res['data']['content'] | |
| #bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"]) | |
| history[-1][1] = "" | |
| for thing in history: | |
| print(thing) | |
| print('------------------------------------------------------------------------') | |
| for character in bot_message: | |
| history[-1][1] += character | |
| time.sleep(0.05) | |
| yield history | |
| msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then( | |
| bot, chatbot, chatbot | |
| ) | |
| clear.click(lambda: None, None, chatbot, queue=False) | |
| demo.queue() | |
| demo.launch() |