Spaces:
Build error
Build error
Commit ·
52f4bdb
1
Parent(s): 345952e
done
Browse files4 unmodified lines56789101110 unmodified lines222324252627282925 unmodified lines555657585960616263646566676869701 unmodified line727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491504 unmodified linesimport os# Initialize the Inference Client with your model# Ensure you have set the HUGGINGFACE_API_TOKEN environment variableclient = InferenceClient("HuggingFaceH4/zephyr-7b-beta", token=os.getenv("HUGGINGFACE_API_TOKEN"))def respond(10 unmodified lines# Define the system message internally (hidden from the user)system_message = ("You are a hiring manager negotiating a job offer. ""Your goal is to offer a fair salary based on the candidate's negotiation skills. ""Start the negotiation with an initial offer of $60,000.")# Initialize the messages with the system prompt25 unmodified lines# Append AI response to historyhistory.append((message, response))# Simple logic to determine negotiation success based on AI's responsesuccess_keywords = ["agreed", "accepted", "increase", "raised", "enhanced", "approved", "offer", "agree", "accept"]# Check if any success keywords are in the AI's response (case-insensitive)if any(keyword.lower() in response.lower() for keyword in success_keywords):# Increment the salary by a fixed amountincrement = 5000 # Fixed increment; modify as desiredcurrent_salary += increment# Note: We're NOT appending any message to the chat history here# The salary update is handled separatelyreturn history, current_salary1 unmodified line"""Function to reset the game to initial state."""return [], 60000 # Reset history and salary to 60k# Define the Gradio Blocks layoutwith gr.Blocks() as demo:gr.Markdown("# 💼 Salary Negotiation Game")gr.Markdown("""**Objective:** Negotiate with the employer to increase your salary from \$60,000.**Instructions:**- Use the chat interface to negotiate.- If you negotiate successfully, your salary will increase.- Aim to reach the highest salary possible through effective negotiation.""")with gr.Row():with gr.Column(scale=1):# Display the current salarysalary_display = gr.Number(value=60000,label="Current Salary (\$)",interactive=False,precision=0)# Reset button to restart the gamereset_btn = gr.Button("Reset Game")reset_btn.click(fn=reset_game, inputs=None, outputs=[gr.State(), salary_display])with gr.Column(scale=3):# Chat history to keep track of the conversationchat_history = gr.State([])# Chat Interfacechatbot = gr.Chatbot()# User inputuser_input = gr.Textbox(label="Your Message",placeholder="Enter your negotiation message here...",lines=2)send_button = gr.Button("Send")def handle_message(message, history, max_tokens, temperature, top_p, current_salary):"""Handles user messages and updates the conversation history and salary."""history, current_salary = respond(message, history, max_tokens, temperature, top_p, current_salary)return history, current_salary, "" # Clear the input textboxsend_button.click(handle_message,inputs=[user_input,chat_history,gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max New Tokens"),gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),gr.Slider(minimum=0.1,maximum=1.0,value=0.95,step=0.05,label="Top-p (nucleus sampling)",),salary_display],outputs=[chatbot,salary_display,user_input # Clear the input textbox])gr.Markdown("""4 unmodified lines567891010 unmodified lines212223242526272825 unmodified lines54555657585960616263646566676869707172737475761 unmodified line787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391404 unmodified linesimport os# Initialize the Inference Client with your modelclient = InferenceClient("HuggingFaceH4/zephyr-7b-beta", token=os.getenv("HUGGINGFACE_API_TOKEN"))def respond(10 unmodified lines# Define the system message internally (hidden from the user)system_message = ("You are a hiring manager negotiating a job offer. ""Your initial offer is $60,000. Only increase the salary if the candidate provides compelling reasons. ""Communicate any salary offers explicitly in your responses, and only mention the salary when you are making an offer.")# Initialize the messages with the system prompt25 unmodified lines# Append AI response to historyhistory.append((message, response))# Extract salary offers from AI's response# Use regex to find salary amounts in the responsesalary_pattern = r'\$\s?([\d,]+)'matches = re.findall(salary_pattern, response)offered_salary = Noneif matches:# Convert extracted salary strings to integersfor match in matches:salary_str = match.replace(',', '').strip()try:salary_value = int(salary_str)if salary_value > current_salary:offered_salary = salary_valuecurrent_salary = offered_salaryexcept ValueError:continue # Ignore invalid salary stringsreturn history, current_salary1 unmodified line"""Function to reset the game to initial state."""return [], 60000 # Reset history and salary to $60,000# Define the Gradio Blocks layoutwith gr.Blocks() as demo:gr.Markdown("# 💼 Salary Negotiation Game")gr.Markdown("""**Objective:** Negotiate your salary starting from $60,000.**Instructions:**- Use the chat to negotiate your salary with the hiring manager.- Provide compelling reasons for a higher salary.- The hiring manager will consider your arguments and may adjust the offer.""")# Chat history to keep track of the conversationchat_history = gr.State([])# Chat Interfacechatbot = gr.Chatbot()# User inputuser_input = gr.Textbox(label="Your Message",placeholder="Enter your negotiation message here...",lines=2)send_button = gr.Button("Send")def handle_message(message, history, max_tokens, temperature, top_p, current_salary):"""Handles user messages and updates the conversation history and salary."""history, current_salary = respond(message, history, max_tokens, temperature, top_p, current_salary)return history, "", current_salarysend_button.click(handle_message,inputs=[user_input,chat_history,gr.Number(value=512, label="Max New Tokens"),gr.Number(value=0.7, label="Temperature"),gr.Number(value=0.95, label="Top-p"),gr.State(60000) # Initial salary],outputs=[chatbot,user_input, # Clear the input textboxgr.State() # Update the salary internally])# Reset button to restart the gamereset_btn = gr.Button("Reset Game")reset_btn.click(fn=reset_game, inputs=None, outputs=[chat_history, gr.State(60000)])gr.Markdown("""
app.py+64-74