Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,11 @@ enable_btn = gr.Button.update(interactive=True)
|
|
| 9 |
# Load chatbot URLs and model names from a JSON file
|
| 10 |
with open('chatbot_urls.json', 'r') as file:
|
| 11 |
chatbots = json.load(file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Initialize or get user-specific ELO ratings
|
| 14 |
def get_user_elo_ratings(state):
|
|
@@ -79,7 +84,7 @@ def chat_with_bots(user_input, state):
|
|
| 79 |
return bot1_response, bot2_response
|
| 80 |
|
| 81 |
def update_ratings(state, winner_index):
|
| 82 |
-
elo_ratings = get_user_elo_ratings()
|
| 83 |
bot_names = list(chatbots.keys())
|
| 84 |
winner = state['last_bots'][winner_index]
|
| 85 |
loser = state['last_bots'][1 - winner_index]
|
|
@@ -91,12 +96,8 @@ def update_ratings(state, winner_index):
|
|
| 91 |
def vote_up_model(state, chatbot):
|
| 92 |
update_message = update_ratings(state, 0)
|
| 93 |
chatbot.append(update_message)
|
| 94 |
-
return chatbot
|
| 95 |
|
| 96 |
-
def vote_down_model(state, chatbot):
|
| 97 |
-
update_message = update_ratings(state, 1)
|
| 98 |
-
chatbot.append(update_message)
|
| 99 |
-
return chatbot
|
| 100 |
def user_ask(state, chatbot1, chatbot2, textbox):
|
| 101 |
global enable_btn
|
| 102 |
user_input = textbox
|
|
@@ -144,11 +145,13 @@ with gr.Blocks() as demo:
|
|
| 144 |
upvote_btn_b = gr.Button(value="👍 Upvote B",interactive=False)
|
| 145 |
|
| 146 |
textbox = gr.Textbox(placeholder="Enter your prompt (up to 200 characters)", max_chars=200)
|
| 147 |
-
|
| 148 |
-
|
|
|
|
|
|
|
| 149 |
textbox.submit(user_ask, inputs=[state, chatbot1, chatbot2, textbox], outputs=[state, chatbot1, chatbot2, textbox,upvote_btn_a,upvote_btn_b])
|
| 150 |
submit_btn.click(user_ask, inputs=[state, chatbot1, chatbot2, textbox], outputs=[state, chatbot1, chatbot2, textbox,upvote_btn_a,upvote_btn_b])
|
| 151 |
-
upvote_btn_a.click(vote_up_model, inputs=[state, chatbot1], outputs=[chatbot1])
|
| 152 |
-
upvote_btn_b.click(vote_down_model, inputs=[state, chatbot2], outputs=[chatbot2])
|
| 153 |
|
| 154 |
demo.launch()
|
|
|
|
| 9 |
# Load chatbot URLs and model names from a JSON file
|
| 10 |
with open('chatbot_urls.json', 'r') as file:
|
| 11 |
chatbots = json.load(file)
|
| 12 |
+
def clear_chat(state):
|
| 13 |
+
if state is not None:
|
| 14 |
+
state = {}
|
| 15 |
+
return state, None,None,gr.Button.update(interactive=False),gr.Button.update(interactive=False)
|
| 16 |
+
|
| 17 |
|
| 18 |
# Initialize or get user-specific ELO ratings
|
| 19 |
def get_user_elo_ratings(state):
|
|
|
|
| 84 |
return bot1_response, bot2_response
|
| 85 |
|
| 86 |
def update_ratings(state, winner_index):
|
| 87 |
+
elo_ratings = get_user_elo_ratings(state)
|
| 88 |
bot_names = list(chatbots.keys())
|
| 89 |
winner = state['last_bots'][winner_index]
|
| 90 |
loser = state['last_bots'][1 - winner_index]
|
|
|
|
| 96 |
def vote_up_model(state, chatbot):
|
| 97 |
update_message = update_ratings(state, 0)
|
| 98 |
chatbot.append(update_message)
|
| 99 |
+
return chatbot, gr.Button.update(interactive=False),gr.Button.update(interactive=False) # Disable voting buttons
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
def user_ask(state, chatbot1, chatbot2, textbox):
|
| 102 |
global enable_btn
|
| 103 |
user_input = textbox
|
|
|
|
| 145 |
upvote_btn_b = gr.Button(value="👍 Upvote B",interactive=False)
|
| 146 |
|
| 147 |
textbox = gr.Textbox(placeholder="Enter your prompt (up to 200 characters)", max_chars=200)
|
| 148 |
+
with gr.Row():
|
| 149 |
+
submit_btn = gr.Button(value="Send")
|
| 150 |
+
reset_btn = gr.Button(value="Reset")
|
| 151 |
+
reset_btn.click(clear_chat, inputs=[state], outputs=[state, chatbot1, chatbot2, upvote_btn_a, upvote_btn_b])
|
| 152 |
textbox.submit(user_ask, inputs=[state, chatbot1, chatbot2, textbox], outputs=[state, chatbot1, chatbot2, textbox,upvote_btn_a,upvote_btn_b])
|
| 153 |
submit_btn.click(user_ask, inputs=[state, chatbot1, chatbot2, textbox], outputs=[state, chatbot1, chatbot2, textbox,upvote_btn_a,upvote_btn_b])
|
| 154 |
+
upvote_btn_a.click(vote_up_model, inputs=[state, chatbot1], outputs=[chatbot1,upvote_btn_a,upvote_btn_b])
|
| 155 |
+
upvote_btn_b.click(vote_down_model, inputs=[state, chatbot2], outputs=[chatbot2,upvote_btn_a,upvote_btn_b])
|
| 156 |
|
| 157 |
demo.launch()
|