Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -13,8 +13,6 @@ with open('chatbot_urls.json', 'r') as file:
|
|
13 |
|
14 |
# Initialize or get user-specific ELO ratings
|
15 |
def get_user_elo_ratings(state):
|
16 |
-
if 'elo_ratings' not in state:
|
17 |
-
state['elo_ratings'] = read_elo_ratings()
|
18 |
return state['elo_ratings']
|
19 |
|
20 |
# Read ELO ratings from file (thread-safe)
|
@@ -49,17 +47,19 @@ def get_bot_response(url, prompt):
|
|
49 |
response = requests.post(url, json=payload, headers=headers)
|
50 |
return response.json()['output'][0]['generated_text'].replace(prompt,"")
|
51 |
|
52 |
-
def chat_with_bots(user_input):
|
53 |
bot_names = list(chatbots.keys())
|
54 |
random.shuffle(bot_names)
|
55 |
bot1_url, bot2_url = chatbots[bot_names[0]], chatbots[bot_names[1]]
|
56 |
-
|
|
|
|
|
|
|
57 |
bot1_response = get_bot_response(bot1_url, user_input)
|
58 |
bot2_response = get_bot_response(bot2_url, user_input)
|
59 |
|
60 |
return bot1_response, bot2_response
|
61 |
|
62 |
-
|
63 |
def update_ratings(state, winner_index):
|
64 |
elo_ratings = get_user_elo_ratings()
|
65 |
bot_names = list(chatbots.keys())
|
@@ -92,7 +92,8 @@ def user_ask(state, chatbot1, chatbot2, textbox, upvote_btn_a, upvote_btn_b):
|
|
92 |
upvote_btn_a.interactive = True
|
93 |
upvote_btn_b.interactive = True
|
94 |
print(state, chatbot1, chatbot2, "", upvote_btn_a, upvote_btn_b)
|
95 |
-
|
|
|
96 |
return state, chatbot1, chatbot2, "", upvote_btn_a, upvote_btn_b
|
97 |
|
98 |
# ... [Rest of your existing functions] ...
|
|
|
13 |
|
14 |
# Initialize or get user-specific ELO ratings
|
15 |
def get_user_elo_ratings(state):
|
|
|
|
|
16 |
return state['elo_ratings']
|
17 |
|
18 |
# Read ELO ratings from file (thread-safe)
|
|
|
47 |
response = requests.post(url, json=payload, headers=headers)
|
48 |
return response.json()['output'][0]['generated_text'].replace(prompt,"")
|
49 |
|
50 |
+
def chat_with_bots(user_input, state):
|
51 |
bot_names = list(chatbots.keys())
|
52 |
random.shuffle(bot_names)
|
53 |
bot1_url, bot2_url = chatbots[bot_names[0]], chatbots[bot_names[1]]
|
54 |
+
|
55 |
+
# Update the state with the names of the last bots
|
56 |
+
state.update({'last_bots': [bot_names[0], bot_names[1]]})
|
57 |
+
|
58 |
bot1_response = get_bot_response(bot1_url, user_input)
|
59 |
bot2_response = get_bot_response(bot2_url, user_input)
|
60 |
|
61 |
return bot1_response, bot2_response
|
62 |
|
|
|
63 |
def update_ratings(state, winner_index):
|
64 |
elo_ratings = get_user_elo_ratings()
|
65 |
bot_names = list(chatbots.keys())
|
|
|
92 |
upvote_btn_a.interactive = True
|
93 |
upvote_btn_b.interactive = True
|
94 |
print(state, chatbot1, chatbot2, "", upvote_btn_a, upvote_btn_b)
|
95 |
+
updated_elo_ratings = get_user_elo_ratings(state)
|
96 |
+
state.update({'elo_ratings': updated_elo_ratings})
|
97 |
return state, chatbot1, chatbot2, "", upvote_btn_a, upvote_btn_b
|
98 |
|
99 |
# ... [Rest of your existing functions] ...
|