Spaces:
Running
Running
User_id fix
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import re
|
|
| 3 |
import random
|
| 4 |
from collections import defaultdict
|
| 5 |
from datetime import datetime, timezone
|
|
|
|
| 6 |
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
|
|
@@ -60,13 +61,21 @@ def load_model_data():
|
|
| 60 |
|
| 61 |
model_data = load_model_data()
|
| 62 |
|
| 63 |
-
current_session_id = 0
|
| 64 |
|
| 65 |
-
|
| 66 |
-
def get_new_session_id():
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
|
| 72 |
def store_vote_data(prompt, response_a, response_b, model_a, model_b, winner, judge_id):
|
|
@@ -265,7 +274,7 @@ def get_leaderboard():
|
|
| 265 |
|
| 266 |
# Sort leaderboard by ELO score in descending order
|
| 267 |
leaderboard.sort(key=lambda x: float(x["ELO Score"]), reverse=True)
|
| 268 |
-
|
| 269 |
return leaderboard
|
| 270 |
|
| 271 |
|
|
@@ -434,7 +443,7 @@ def get_random_metric():
|
|
| 434 |
|
| 435 |
|
| 436 |
with gr.Blocks(theme="default", css=CSS_STYLES) as demo:
|
| 437 |
-
judge_id = gr.State(get_new_session_id())
|
| 438 |
gr.Markdown(MAIN_TITLE)
|
| 439 |
gr.Markdown(HOW_IT_WORKS)
|
| 440 |
|
|
|
|
| 3 |
import random
|
| 4 |
from collections import defaultdict
|
| 5 |
from datetime import datetime, timezone
|
| 6 |
+
import hashlib
|
| 7 |
|
| 8 |
from dotenv import load_dotenv
|
| 9 |
|
|
|
|
| 61 |
|
| 62 |
model_data = load_model_data()
|
| 63 |
|
|
|
|
| 64 |
|
| 65 |
+
# Generate a unique session ID based on the user's IP address
|
| 66 |
+
def get_new_session_id(request: gr.Request):
|
| 67 |
+
"""Generate a unique session ID based on the user's IP address."""
|
| 68 |
+
if "cf-connecting-ip" in request.headers:
|
| 69 |
+
ip = request.headers["cf-connecting-ip"]
|
| 70 |
+
elif "x-forwarded-for" in request.headers:
|
| 71 |
+
ip = request.headers["x-forwarded-for"]
|
| 72 |
+
if "," in ip:
|
| 73 |
+
ip = ip.split(",")[0]
|
| 74 |
+
else:
|
| 75 |
+
ip = request.client.host
|
| 76 |
+
|
| 77 |
+
# Create a hash of the IP to maintain privacy
|
| 78 |
+
return f"user_{hashlib.md5(ip.encode()).hexdigest()[:8]}"
|
| 79 |
|
| 80 |
|
| 81 |
def store_vote_data(prompt, response_a, response_b, model_a, model_b, winner, judge_id):
|
|
|
|
| 274 |
|
| 275 |
# Sort leaderboard by ELO score in descending order
|
| 276 |
leaderboard.sort(key=lambda x: float(x["ELO Score"]), reverse=True)
|
| 277 |
+
|
| 278 |
return leaderboard
|
| 279 |
|
| 280 |
|
|
|
|
| 443 |
|
| 444 |
|
| 445 |
with gr.Blocks(theme="default", css=CSS_STYLES) as demo:
|
| 446 |
+
judge_id = gr.State(lambda: get_new_session_id(gr.Request()))
|
| 447 |
gr.Markdown(MAIN_TITLE)
|
| 448 |
gr.Markdown(HOW_IT_WORKS)
|
| 449 |
|