rwitz commited on
Commit
41b12a8
Β·
1 Parent(s): 360577c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -12,7 +12,7 @@ with open('chatbot_urls.json', 'r') as file:
12
 
13
  # Initialize or get user-specific ELO ratings
14
  def get_user_elo_ratings(state):
15
- return state.get('elo_ratings', {model: 1200 for model in chatbots.keys()})
16
 
17
  # Read and write ELO ratings to file (thread-safe)
18
  def read_elo_ratings():
@@ -29,7 +29,7 @@ def write_elo_ratings(elo_ratings):
29
  # Function to get bot response
30
  def format_chatml_prompt(state):
31
  chatml_prompt = ""
32
- for message in state.get("history", []):
33
  chatml_prompt += f"<|im_start|> "+message['role']+"- "+ message['content']+"<|im_end|>\n"
34
  return chatml_prompt
35
  def get_bot_response(url, prompt):
@@ -84,6 +84,7 @@ def vote_down_model(state, chatbot):
84
  chatbot.append(update_message)
85
  return chatbot
86
  def user_ask(state, chatbot1, chatbot2, textbox):
 
87
  user_input = textbox
88
  if len(user_input) > 200:
89
  user_input = user_input[:200] # Limit user input to 200 characters
@@ -110,7 +111,7 @@ def user_ask(state, chatbot1, chatbot2, textbox):
110
 
111
  # Format the conversation in ChatML format
112
 
113
- return state, chatbot1, chatbot2, textbox
114
 
115
  # Gradio interface setup
116
  with gr.Blocks() as demo:
@@ -119,17 +120,17 @@ with gr.Blocks() as demo:
119
  with gr.Row():
120
  with gr.Column():
121
  chatbot1 = gr.Chatbot(label='Model A').style(height=600)
122
- upvote_btn_a = gr.Button(value="πŸ‘ Upvote A")
123
 
124
  with gr.Column():
125
  chatbot2 = gr.Chatbot(label='Model B').style(height=600)
126
- upvote_btn_b = gr.Button(value="πŸ‘ Upvote B")
127
 
128
  textbox = gr.Textbox(placeholder="Enter your prompt (up to 200 characters)", max_chars=200)
129
  submit_btn = gr.Button(value="Send")
130
 
131
- textbox.submit(user_ask, inputs=[state, chatbot1, chatbot2, textbox], outputs=[state, chatbot1, chatbot2, textbox])
132
- submit_btn.click(user_ask, inputs=[state, chatbot1, chatbot2, textbox], outputs=[state, chatbot1, chatbot2, textbox])
133
  upvote_btn_a.click(vote_up_model, inputs=[state, chatbot1], outputs=[chatbot1])
134
  upvote_btn_b.click(vote_down_model, inputs=[state, chatbot2], outputs=[chatbot2])
135
 
 
12
 
13
  # Initialize or get user-specific ELO ratings
14
  def get_user_elo_ratings(state):
15
+ return state['elo_ratings']
16
 
17
  # Read and write ELO ratings to file (thread-safe)
18
  def read_elo_ratings():
 
29
  # Function to get bot response
30
  def format_chatml_prompt(state):
31
  chatml_prompt = ""
32
+ for message in state["history"]
33
  chatml_prompt += f"<|im_start|> "+message['role']+"- "+ message['content']+"<|im_end|>\n"
34
  return chatml_prompt
35
  def get_bot_response(url, prompt):
 
84
  chatbot.append(update_message)
85
  return chatbot
86
  def user_ask(state, chatbot1, chatbot2, textbox):
87
+ global enable_btn
88
  user_input = textbox
89
  if len(user_input) > 200:
90
  user_input = user_input[:200] # Limit user input to 200 characters
 
111
 
112
  # Format the conversation in ChatML format
113
 
114
+ return state, chatbot1, chatbot2, textbox,enable_btn,enable_btn
115
 
116
  # Gradio interface setup
117
  with gr.Blocks() as demo:
 
120
  with gr.Row():
121
  with gr.Column():
122
  chatbot1 = gr.Chatbot(label='Model A').style(height=600)
123
+ upvote_btn_a = gr.Button(value="πŸ‘ Upvote A",interactive=False)
124
 
125
  with gr.Column():
126
  chatbot2 = gr.Chatbot(label='Model B').style(height=600)
127
+ upvote_btn_b = gr.Button(value="πŸ‘ Upvote B",interactive=False)
128
 
129
  textbox = gr.Textbox(placeholder="Enter your prompt (up to 200 characters)", max_chars=200)
130
  submit_btn = gr.Button(value="Send")
131
 
132
+ textbox.submit(user_ask, inputs=[state, chatbot1, chatbot2, textbox], outputs=[state, chatbot1, chatbot2, textbox,upvote_btn_a,upvote_btn_b])
133
+ submit_btn.click(user_ask, inputs=[state, chatbot1, chatbot2, textbox], outputs=[state, chatbot1, chatbot2, textbox,upvote_btn_a,upvote_btn_b])
134
  upvote_btn_a.click(vote_up_model, inputs=[state, chatbot1], outputs=[chatbot1])
135
  upvote_btn_b.click(vote_down_model, inputs=[state, chatbot2], outputs=[chatbot2])
136