Spaces:
No application file
No application file
| import openai | |
| import numpy as np | |
| from langchain.chat_models import ChatOpenAI | |
| from langchain.prompts import ChatPromptTemplate | |
| import gradio as gr | |
| import os | |
| def get_completion(relation, emotion, resolution, context): | |
| openai_api_key = "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" | |
| chat = ChatOpenAI(temperature=0.0, model='gpt-4', openai_api_key=openai_api_key) | |
| template_string = ''' | |
| Your task is to provide some recommendations to resolve a conflict between two {relation}. Below is more info: | |
| Emotional Impact: {emotion} | |
| Goal: {resolution} | |
| Context: {context} | |
| Please give some recommendations on how the two {relation} can reach their goal, given the emotional impact and context. Don't provide examples. Don't make general statements that apply in any situation. Please consider the typical environments where the {relation} interact in your answer and be specific on where/how exactly to go about resolving the conflict. Keep in mind the emotional impact - if the conflict is overwhelming then more serious measures may be needed. But if the emotional impact is low then your recommendations should be more casual - no need for a third party to get involved. | |
| Provide your response in a short paragraph, roughly 5-10 sentences. | |
| ''' | |
| prompt_template = ChatPromptTemplate.from_template(template_string) | |
| message = prompt_template.format_messages( | |
| relation = relation, | |
| emotion = emotion, | |
| resolution = resolution, | |
| context = context | |
| ) | |
| response = chat(message) | |
| return response.content | |
| relat = ['Co-workers', 'Family Members', 'Friends', 'Romantic partners'] | |
| emot = ['Calm', 'Concerned', 'Annoyed', 'Upset', 'Overwhelmed'] | |
| res = ['Compromise - Both parties make concessions to reach a mutual agreement. Useful when both sides have significant stakes and neither can fully satisfy their desires without the cooperation of the other.', | |
| 'Confrontation - Directly addressing the conflict head-on. This may be necessary when one side believes strongly in their stance and feels the need to stand firm.', | |
| 'Understanding - The goal is to better understand the perspective of the other party, without necessarily seeking to change or challenge it. This is particularly effective for clarifying miscommunications or misconceptions.', | |
| 'Avoidance - Sometimes it is better to postpone or sidestep a conflict if it is not critical, especially if the timing is not right or if more preparation is needed.', | |
| 'Accommodation - One party willingly yields to the desires of the other, perhaps because they deem the issue less significant for them or they prioritize the relationship over the specific disagreement.' | |
| ] | |
| with gr.Blocks() as main: | |
| mk = gr.Markdown(value='# AiOS Inter Accomplish') | |
| relat_sel = gr.Dropdown(label='Relationship Category', choices=relat) | |
| emot_sel = gr.Dropdown(label='Emotional Impact', choices=emot) | |
| res_sel = gr.Dropdown(label='Resolution Type', choices=res) | |
| context = gr.Textbox(value='', lines=5, label='Other Info') | |
| sub = gr.Button(value='Submit') | |
| ans = gr.TextArea(label='Response', value='') | |
| out = sub.click(get_completion, inputs=[relat_sel, emot_sel, res_sel, context], outputs=ans, show_progress=True, scroll_to_output=True) | |
| main.launch(debug=True) | |