Spaces:
Sleeping
Sleeping
Commit
·
52f4bdb
1
Parent(s):
345952e
done
Browse files
app.py
CHANGED
|
@@ -5,7 +5,6 @@ import traceback
|
|
| 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(
|
|
@@ -22,8 +21,8 @@ def respond(
|
|
| 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
|
| 26 |
-
"
|
| 27 |
)
|
| 28 |
|
| 29 |
# Initialize the messages with the system prompt
|
|
@@ -55,16 +54,23 @@ def respond(
|
|
| 55 |
# Append AI response to history
|
| 56 |
history.append((message, response))
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
return history, current_salary
|
| 70 |
|
|
@@ -72,79 +78,63 @@ def reset_game():
|
|
| 72 |
"""
|
| 73 |
Function to reset the game to initial state.
|
| 74 |
"""
|
| 75 |
-
return [], 60000 # Reset history and salary to
|
| 76 |
|
| 77 |
# Define the Gradio Blocks layout
|
| 78 |
with gr.Blocks() as demo:
|
| 79 |
gr.Markdown("# 💼 Salary Negotiation Game")
|
| 80 |
gr.Markdown(
|
| 81 |
"""
|
| 82 |
-
**Objective:** Negotiate
|
| 83 |
-
|
| 84 |
**Instructions:**
|
| 85 |
-
- Use the chat
|
| 86 |
-
-
|
| 87 |
-
-
|
| 88 |
"""
|
| 89 |
)
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
# Display the current salary
|
| 94 |
-
salary_display = gr.Number(
|
| 95 |
-
value=60000,
|
| 96 |
-
label="Current Salary (\$)",
|
| 97 |
-
interactive=False,
|
| 98 |
-
precision=0
|
| 99 |
-
)
|
| 100 |
-
# Reset button to restart the game
|
| 101 |
-
reset_btn = gr.Button("Reset Game")
|
| 102 |
-
reset_btn.click(fn=reset_game, inputs=None, outputs=[gr.State(), salary_display])
|
| 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 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
outputs=[
|
| 143 |
-
chatbot,
|
| 144 |
-
salary_display,
|
| 145 |
-
user_input # Clear the input textbox
|
| 146 |
-
]
|
| 147 |
-
)
|
| 148 |
|
| 149 |
gr.Markdown(
|
| 150 |
"""
|
|
|
|
| 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(
|
|
|
|
| 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. Only increase the salary if the candidate provides compelling reasons. "
|
| 25 |
+
"Communicate any salary offers explicitly in your responses, and only mention the salary when you are making an offer."
|
| 26 |
)
|
| 27 |
|
| 28 |
# Initialize the messages with the system prompt
|
|
|
|
| 54 |
# Append AI response to history
|
| 55 |
history.append((message, response))
|
| 56 |
|
| 57 |
+
# Extract salary offers from AI's response
|
| 58 |
+
# Use regex to find salary amounts in the response
|
| 59 |
+
salary_pattern = r'\$\s?([\d,]+)'
|
| 60 |
+
matches = re.findall(salary_pattern, response)
|
| 61 |
+
offered_salary = None
|
| 62 |
|
| 63 |
+
if matches:
|
| 64 |
+
# Convert extracted salary strings to integers
|
| 65 |
+
for match in matches:
|
| 66 |
+
salary_str = match.replace(',', '').strip()
|
| 67 |
+
try:
|
| 68 |
+
salary_value = int(salary_str)
|
| 69 |
+
if salary_value > current_salary:
|
| 70 |
+
offered_salary = salary_value
|
| 71 |
+
current_salary = offered_salary
|
| 72 |
+
except ValueError:
|
| 73 |
+
continue # Ignore invalid salary strings
|
| 74 |
|
| 75 |
return history, current_salary
|
| 76 |
|
|
|
|
| 78 |
"""
|
| 79 |
Function to reset the game to initial state.
|
| 80 |
"""
|
| 81 |
+
return [], 60000 # Reset history and salary to $60,000
|
| 82 |
|
| 83 |
# Define the Gradio Blocks layout
|
| 84 |
with gr.Blocks() as demo:
|
| 85 |
gr.Markdown("# 💼 Salary Negotiation Game")
|
| 86 |
gr.Markdown(
|
| 87 |
"""
|
| 88 |
+
**Objective:** Negotiate your salary starting from $60,000.
|
| 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 |
+
# Chat history to keep track of the conversation
|
| 98 |
+
chat_history = gr.State([])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
+
# Chat Interface
|
| 101 |
+
chatbot = gr.Chatbot()
|
| 102 |
+
|
| 103 |
+
# User input
|
| 104 |
+
user_input = gr.Textbox(
|
| 105 |
+
label="Your Message",
|
| 106 |
+
placeholder="Enter your negotiation message here...",
|
| 107 |
+
lines=2
|
| 108 |
+
)
|
| 109 |
+
send_button = gr.Button("Send")
|
| 110 |
+
|
| 111 |
+
def handle_message(message, history, max_tokens, temperature, top_p, current_salary):
|
| 112 |
+
"""
|
| 113 |
+
Handles user messages and updates the conversation history and salary.
|
| 114 |
+
"""
|
| 115 |
+
history, current_salary = respond(message, history, max_tokens, temperature, top_p, current_salary)
|
| 116 |
+
return history, "", current_salary
|
| 117 |
+
|
| 118 |
+
send_button.click(
|
| 119 |
+
handle_message,
|
| 120 |
+
inputs=[
|
| 121 |
+
user_input,
|
| 122 |
+
chat_history,
|
| 123 |
+
gr.Number(value=512, label="Max New Tokens"),
|
| 124 |
+
gr.Number(value=0.7, label="Temperature"),
|
| 125 |
+
gr.Number(value=0.95, label="Top-p"),
|
| 126 |
+
gr.State(60000) # Initial salary
|
| 127 |
+
],
|
| 128 |
+
outputs=[
|
| 129 |
+
chatbot,
|
| 130 |
+
user_input, # Clear the input textbox
|
| 131 |
+
gr.State() # Update the salary internally
|
| 132 |
+
]
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
# Reset button to restart the game
|
| 136 |
+
reset_btn = gr.Button("Reset Game")
|
| 137 |
+
reset_btn.click(fn=reset_game, inputs=None, outputs=[chat_history, gr.State(60000)])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
gr.Markdown(
|
| 140 |
"""
|