rwitz commited on
Commit
65b4ef2
1 Parent(s): dfc3b95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -15
app.py CHANGED
@@ -3,7 +3,6 @@ import requests
3
  import os
4
  import json
5
  import random
6
- import threading
7
  from elo import update_elo_ratings # Custom function for ELO ratings
8
 
9
  # Load the chatbot URLs and their respective model names from a JSON file
@@ -14,27 +13,24 @@ with open('chatbot_urls.json', 'r') as file:
14
  user_data = threading.local()
15
 
16
  # Initialize or get user-specific ELO ratings
17
- def get_user_elo_ratings():
18
- if not hasattr(user_data, 'elo_ratings'):
19
- user_data.elo_ratings = read_elo_ratings()
20
- return user_data.elo_ratings
21
 
22
  # Read ELO ratings from file (thread-safe)
23
  def read_elo_ratings():
24
- elo_ratings = {}
25
- with threading.Lock():
26
- try:
27
- with open('elo_ratings.json', 'r') as file:
28
- elo_ratings = json.load(file)
29
- except FileNotFoundError:
30
- elo_ratings = {model: 1200 for model in chatbots.keys()}
31
  return elo_ratings
32
 
33
  # Write ELO ratings to file (thread-safe)
34
  def write_elo_ratings(elo_ratings):
35
- with threading.Lock():
36
- with open('elo_ratings.json', 'w') as file:
37
- json.dump(elo_ratings, file, indent=4)
38
 
39
  def get_bot_response(url, prompt):
40
  payload = {
@@ -101,6 +97,7 @@ def user_ask(state, chatbot1, chatbot2, textbox, upvote_btn_a, upvote_btn_b):
101
  upvote_btn_a.interactive = True
102
  upvote_btn_b.interactive = True
103
  print(state, chatbot1, chatbot2, "", upvote_btn_a, upvote_btn_b)
 
104
  return state, chatbot1, chatbot2, "", upvote_btn_a, upvote_btn_b
105
 
106
  # ... [Rest of your existing functions] ...
 
3
  import os
4
  import json
5
  import random
 
6
  from elo import update_elo_ratings # Custom function for ELO ratings
7
 
8
  # Load the chatbot URLs and their respective model names from a JSON file
 
13
  user_data = threading.local()
14
 
15
  # Initialize or get user-specific ELO ratings
16
+ def get_user_elo_ratings(state):
17
+ if 'elo_ratings' not in state:
18
+ state['elo_ratings'] = read_elo_ratings()
19
+ return state['elo_ratings']
20
 
21
  # Read ELO ratings from file (thread-safe)
22
  def read_elo_ratings():
23
+ try:
24
+ with open('elo_ratings.json', 'r') as file:
25
+ elo_ratings = json.load(file)
26
+ except FileNotFoundError:
27
+ elo_ratings = {model: 1200 for model in chatbots.keys()}
 
 
28
  return elo_ratings
29
 
30
  # Write ELO ratings to file (thread-safe)
31
  def write_elo_ratings(elo_ratings):
32
+ with open('elo_ratings.json', 'w') as file:
33
+ json.dump(elo_ratings, file, indent=4)
 
34
 
35
  def get_bot_response(url, prompt):
36
  payload = {
 
97
  upvote_btn_a.interactive = True
98
  upvote_btn_b.interactive = True
99
  print(state, chatbot1, chatbot2, "", upvote_btn_a, upvote_btn_b)
100
+ state['elo_ratings'] = get_user_elo_ratings(state)
101
  return state, chatbot1, chatbot2, "", upvote_btn_a, upvote_btn_b
102
 
103
  # ... [Rest of your existing functions] ...