Spaces:
Sleeping
Sleeping
Commit
·
5bd35a5
1
Parent(s):
52f4bdb
done
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import traceback
|
|
5 |
import os
|
6 |
|
7 |
# Initialize the Inference Client with your model
|
|
|
8 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta", token=os.getenv("HUGGINGFACE_API_TOKEN"))
|
9 |
|
10 |
def respond(
|
@@ -16,13 +17,15 @@ def respond(
|
|
16 |
current_salary
|
17 |
):
|
18 |
"""
|
19 |
-
|
20 |
"""
|
21 |
# Define the system message internally (hidden from the user)
|
22 |
system_message = (
|
23 |
"You are a hiring manager negotiating a job offer. "
|
24 |
-
"Your initial offer is $60,000.
|
25 |
-
"
|
|
|
|
|
26 |
)
|
27 |
|
28 |
# Initialize the messages with the system prompt
|
@@ -38,9 +41,9 @@ def respond(
|
|
38 |
# Append the latest user message
|
39 |
messages.append({"role": "user", "content": message})
|
40 |
|
41 |
-
# Generate the AI response
|
42 |
try:
|
43 |
-
|
44 |
messages,
|
45 |
max_tokens=max_tokens,
|
46 |
temperature=temperature,
|
@@ -48,35 +51,69 @@ def respond(
|
|
48 |
stop=None
|
49 |
).get("choices")[0].get("message").get("content")
|
50 |
except Exception as e:
|
51 |
-
|
52 |
traceback.print_exc()
|
53 |
|
54 |
# Append AI response to history
|
55 |
-
history.append((message,
|
56 |
-
|
57 |
-
#
|
58 |
-
#
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
return history, current_salary
|
76 |
|
77 |
def reset_game():
|
78 |
"""
|
79 |
-
|
80 |
"""
|
81 |
return [], 60000 # Reset history and salary to $60,000
|
82 |
|
@@ -85,57 +122,65 @@ with gr.Blocks() as demo:
|
|
85 |
gr.Markdown("# 💼 Salary Negotiation Game")
|
86 |
gr.Markdown(
|
87 |
"""
|
88 |
-
**Objective:** Negotiate your salary starting from
|
89 |
-
|
90 |
**Instructions:**
|
91 |
-
- Use the chat to negotiate your salary with the hiring manager.
|
92 |
- Provide compelling reasons for a higher salary.
|
93 |
- The hiring manager will consider your arguments and may adjust the offer.
|
94 |
"""
|
95 |
)
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
gr.Markdown(
|
140 |
"""
|
141 |
---
|
|
|
5 |
import os
|
6 |
|
7 |
# Initialize the Inference Client with your model
|
8 |
+
# Ensure you have set the HUGGINGFACE_API_TOKEN environment variable
|
9 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta", token=os.getenv("HUGGINGFACE_API_TOKEN"))
|
10 |
|
11 |
def respond(
|
|
|
17 |
current_salary
|
18 |
):
|
19 |
"""
|
20 |
+
Handles the negotiation conversation and assesses salary changes.
|
21 |
"""
|
22 |
# Define the system message internally (hidden from the user)
|
23 |
system_message = (
|
24 |
"You are a hiring manager negotiating a job offer. "
|
25 |
+
"Your initial offer is $60,000. "
|
26 |
+
"Only increase the salary if the candidate provides compelling reasons. "
|
27 |
+
"Communicate any salary offers explicitly in your responses, "
|
28 |
+
"and only mention the salary when you are making an offer."
|
29 |
)
|
30 |
|
31 |
# Initialize the messages with the system prompt
|
|
|
41 |
# Append the latest user message
|
42 |
messages.append({"role": "user", "content": message})
|
43 |
|
44 |
+
# Generate the AI response (Negotiation Interaction)
|
45 |
try:
|
46 |
+
ai_response = client.chat_completion(
|
47 |
messages,
|
48 |
max_tokens=max_tokens,
|
49 |
temperature=temperature,
|
|
|
51 |
stop=None
|
52 |
).get("choices")[0].get("message").get("content")
|
53 |
except Exception as e:
|
54 |
+
ai_response = f"An error occurred while communicating with the AI: {e}"
|
55 |
traceback.print_exc()
|
56 |
|
57 |
# Append AI response to history
|
58 |
+
history.append((message, ai_response))
|
59 |
+
|
60 |
+
# Assess the negotiation outcome (Salary Assessment Interaction)
|
61 |
+
# Prepare the assessment prompt
|
62 |
+
assessment_prompt = (
|
63 |
+
"Based on the following conversation, determine if the candidate's salary should be increased, "
|
64 |
+
"decreased, or remain the same compared to $60,000. Respond with one of the following words only: 'increase', 'decrease', or 'same'.\n\n"
|
65 |
+
"Conversation:\n"
|
66 |
+
)
|
67 |
+
|
68 |
+
for user_msg, ai_msg in history:
|
69 |
+
if user_msg:
|
70 |
+
assessment_prompt += f"User: {user_msg}\n"
|
71 |
+
if ai_msg:
|
72 |
+
assessment_prompt += f"AI: {ai_msg}\n"
|
73 |
+
|
74 |
+
# Send the assessment prompt to the AI
|
75 |
+
try:
|
76 |
+
assessment_response = client.chat_completion(
|
77 |
+
[{"role": "user", "content": assessment_prompt}],
|
78 |
+
max_tokens=10,
|
79 |
+
temperature=0,
|
80 |
+
top_p=1.0,
|
81 |
+
stop=None
|
82 |
+
).get("choices")[0].get("message").get("content").strip().lower()
|
83 |
+
except Exception as e:
|
84 |
+
assessment_response = f"An error occurred during salary assessment: {e}"
|
85 |
+
traceback.print_exc()
|
86 |
+
|
87 |
+
# Determine salary adjustment based on assessment
|
88 |
+
if assessment_response == "increase":
|
89 |
+
increment = 5000 # Fixed increment; modify as desired
|
90 |
+
current_salary += increment
|
91 |
+
negotiation_result = f"🎉 Negotiation successful! Your salary has been increased to ${current_salary:,}."
|
92 |
+
# Append the negotiation result to history as an AI message
|
93 |
+
history.append(("", negotiation_result))
|
94 |
+
elif assessment_response == "decrease":
|
95 |
+
decrement = 5000 # Fixed decrement; modify as desired
|
96 |
+
current_salary -= decrement
|
97 |
+
# Ensure salary doesn't go below $60,000
|
98 |
+
if current_salary < 60000:
|
99 |
+
current_salary = 60000
|
100 |
+
negotiation_result = f"⚠️ Negotiation resulted in no change. Your salary remains at $60,000."
|
101 |
+
else:
|
102 |
+
negotiation_result = f"⚠️ Negotiation resulted in a salary decrease to ${current_salary:,}."
|
103 |
+
history.append(("", negotiation_result))
|
104 |
+
elif assessment_response == "same":
|
105 |
+
negotiation_result = f"✅ No change to your salary. It remains at ${current_salary:,}."
|
106 |
+
history.append(("", negotiation_result))
|
107 |
+
else:
|
108 |
+
# If the response is unclear, do not change the salary
|
109 |
+
negotiation_result = "🤔 I couldn't determine the salary adjustment based on the conversation."
|
110 |
+
history.append(("", negotiation_result))
|
111 |
|
112 |
return history, current_salary
|
113 |
|
114 |
def reset_game():
|
115 |
"""
|
116 |
+
Resets the game to its initial state.
|
117 |
"""
|
118 |
return [], 60000 # Reset history and salary to $60,000
|
119 |
|
|
|
122 |
gr.Markdown("# 💼 Salary Negotiation Game")
|
123 |
gr.Markdown(
|
124 |
"""
|
125 |
+
**Objective:** Negotiate your salary starting from \$60,000.
|
126 |
+
|
127 |
**Instructions:**
|
128 |
+
- Use the chat interface to negotiate your salary with the hiring manager.
|
129 |
- Provide compelling reasons for a higher salary.
|
130 |
- The hiring manager will consider your arguments and may adjust the offer.
|
131 |
"""
|
132 |
)
|
133 |
+
|
134 |
+
with gr.Row():
|
135 |
+
with gr.Column(scale=1):
|
136 |
+
# Reset button to restart the game
|
137 |
+
reset_btn = gr.Button("Reset Game")
|
138 |
+
reset_btn.click(fn=reset_game, inputs=None, outputs=[gr.State(), gr.State()])
|
139 |
+
with gr.Column(scale=3):
|
140 |
+
# Chat history to keep track of the conversation
|
141 |
+
chat_history = gr.State([])
|
142 |
+
|
143 |
+
# Chat Interface
|
144 |
+
chatbot = gr.Chatbot()
|
145 |
+
|
146 |
+
# User input
|
147 |
+
user_input = gr.Textbox(
|
148 |
+
label="Your Message",
|
149 |
+
placeholder="Enter your negotiation message here...",
|
150 |
+
lines=2
|
151 |
+
)
|
152 |
+
send_button = gr.Button("Send")
|
153 |
+
|
154 |
+
def handle_message(message, history, max_tokens, temperature, top_p, current_salary):
|
155 |
+
"""
|
156 |
+
Handles user messages, updates the conversation history, and manages salary adjustments.
|
157 |
+
"""
|
158 |
+
history, current_salary = respond(message, history, max_tokens, temperature, top_p, current_salary)
|
159 |
+
return history, current_salary, "" # Clear the input textbox
|
160 |
+
|
161 |
+
send_button.click(
|
162 |
+
handle_message,
|
163 |
+
inputs=[
|
164 |
+
user_input,
|
165 |
+
chat_history,
|
166 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max New Tokens"),
|
167 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
168 |
+
gr.Slider(
|
169 |
+
minimum=0.1,
|
170 |
+
maximum=1.0,
|
171 |
+
value=0.95,
|
172 |
+
step=0.05,
|
173 |
+
label="Top-p (nucleus sampling)",
|
174 |
+
),
|
175 |
+
gr.State(60000) # Initial salary
|
176 |
+
],
|
177 |
+
outputs=[
|
178 |
+
chatbot,
|
179 |
+
gr.State(), # Update the salary state
|
180 |
+
user_input # Clear the input textbox
|
181 |
+
]
|
182 |
+
)
|
183 |
+
|
184 |
gr.Markdown(
|
185 |
"""
|
186 |
---
|