ShafikJR commited on
Commit
401f20d
·
1 Parent(s): b0d28a0

Upload 2 files

Browse files
Files changed (2) hide show
  1. app (2).py +54 -0
  2. requirements.txt +3 -0
app (2).py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import numpy as np
3
+ from langchain.chat_models import ChatOpenAI
4
+ from langchain.prompts import ChatPromptTemplate
5
+ import gradio as gr
6
+ import os
7
+ def get_completion(relation, emotion, resolution, context):
8
+ openai_api_key = "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"
9
+ chat = ChatOpenAI(temperature=0.0, model='gpt-4', openai_api_key=openai_api_key)
10
+
11
+ template_string = '''
12
+ Your task is to provide some recommendations to resolve a conflict between two {relation}. Below is more info:
13
+
14
+ Emotional Impact: {emotion}
15
+ Goal: {resolution}
16
+ Context: {context}
17
+
18
+ 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.
19
+
20
+ Provide your response in a short paragraph, roughly 5-10 sentences.
21
+ '''
22
+
23
+ prompt_template = ChatPromptTemplate.from_template(template_string)
24
+ message = prompt_template.format_messages(
25
+ relation = relation,
26
+ emotion = emotion,
27
+ resolution = resolution,
28
+ context = context
29
+ )
30
+
31
+ response = chat(message)
32
+ return response.content
33
+
34
+ relat = ['Co-workers', 'Family Members', 'Friends', 'Romantic partners']
35
+ emot = ['Calm', 'Concerned', 'Annoyed', 'Upset', 'Overwhelmed']
36
+ 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.',
37
+ '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.',
38
+ '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.',
39
+ '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.',
40
+ '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.'
41
+ ]
42
+
43
+ with gr.Blocks() as main:
44
+ mk = gr.Markdown(value='# AiOS Inter Accomplish')
45
+ relat_sel = gr.Dropdown(label='Relationship Category', choices=relat)
46
+ emot_sel = gr.Dropdown(label='Emotional Impact', choices=emot)
47
+ res_sel = gr.Dropdown(label='Resolution Type', choices=res)
48
+ context = gr.Textbox(value='', lines=5, label='Other Info')
49
+
50
+ sub = gr.Button(value='Submit')
51
+ ans = gr.TextArea(label='Response', value='')
52
+ out = sub.click(get_completion, inputs=[relat_sel, emot_sel, res_sel, context], outputs=ans, show_progress=True, scroll_to_output=True)
53
+
54
+ main.launch(share=False, debug=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ openai
2
+ langchain
3
+ gradio