LuckyHappyFish commited on
Commit
52f4bdb
·
1 Parent(s): 345952e
Files changed (1) hide show
  1. app.py +64 -74
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 goal is to offer a fair salary based on the candidate's negotiation skills. "
26
- "Start the negotiation with an initial offer of $60,000."
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
- # Simple logic to determine negotiation success based on AI's response
59
- success_keywords = ["agreed", "accepted", "increase", "raised", "enhanced", "approved", "offer", "agree", "accept"]
 
 
 
60
 
61
- # Check if any success keywords are in the AI's response (case-insensitive)
62
- if any(keyword.lower() in response.lower() for keyword in success_keywords):
63
- # Increment the salary by a fixed amount
64
- increment = 5000 # Fixed increment; modify as desired
65
- current_salary += increment
66
- # Note: We're NOT appending any message to the chat history here
67
- # The salary update is handled separately
 
 
 
 
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 60k
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 with the employer to increase your salary from \$60,000.
83
-
84
  **Instructions:**
85
- - Use the chat interface to negotiate.
86
- - If you negotiate successfully, your salary will increase.
87
- - Aim to reach the highest salary possible through effective negotiation.
88
  """
89
  )
90
 
91
- with gr.Row():
92
- with gr.Column(scale=1):
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
- with gr.Column(scale=3):
105
- # Chat history to keep track of the conversation
106
- chat_history = gr.State([])
107
-
108
- # Chat Interface
109
- chatbot = gr.Chatbot()
110
-
111
- # User input
112
- user_input = gr.Textbox(
113
- label="Your Message",
114
- placeholder="Enter your negotiation message here...",
115
- lines=2
116
- )
117
- send_button = gr.Button("Send")
118
-
119
- def handle_message(message, history, max_tokens, temperature, top_p, current_salary):
120
- """
121
- Handles user messages and updates the conversation history and salary.
122
- """
123
- history, current_salary = respond(message, history, max_tokens, temperature, top_p, current_salary)
124
- return history, current_salary, "" # Clear the input textbox
125
-
126
- send_button.click(
127
- handle_message,
128
- inputs=[
129
- user_input,
130
- chat_history,
131
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max New Tokens"),
132
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
133
- gr.Slider(
134
- minimum=0.1,
135
- maximum=1.0,
136
- value=0.95,
137
- step=0.05,
138
- label="Top-p (nucleus sampling)",
139
- ),
140
- salary_display
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
  """