Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,40 +21,38 @@ def clear_chat(state):
|
|
| 21 |
|
| 22 |
from datasets import load_dataset
|
| 23 |
import requests
|
|
|
|
| 24 |
|
| 25 |
def get_user_elo_ratings():
|
| 26 |
dataset = load_dataset("rwitz/mistral-elo-ratings", streaming=True)
|
| 27 |
elo_ratings = dataset['train'] # or the relevant split
|
| 28 |
-
|
| 29 |
-
# Check and assign default ELO rating
|
| 30 |
-
default_elo = 1200
|
| 31 |
-
for bot in list(chatbots.keys()):
|
| 32 |
-
if bot not in elo_ratings:
|
| 33 |
-
elo_ratings[bot] = default_elo
|
| 34 |
-
|
| 35 |
return elo_ratings
|
| 36 |
|
| 37 |
def update_elo_rating(player_id, new_rating):
|
| 38 |
# Fetch the current dataset
|
| 39 |
elo_ratings = get_user_elo_ratings()
|
| 40 |
|
| 41 |
-
#
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# Push the updated dataset back to Hugging Face
|
| 45 |
-
# This part is more complex as it involves using Hugging Face's dataset push API.
|
| 46 |
-
# You'll need to use the `requests` library to make a POST request to Hugging Face's API.
|
| 47 |
-
# This is a simplified example:
|
| 48 |
-
updated_data = elo_ratings.to_dict()
|
| 49 |
response = requests.post(
|
| 50 |
"https://huggingface.co/datasets/rwitz/mistral-elo-ratings",
|
| 51 |
-
headers={"Authorization": f"Bearer {os.environ.get('
|
| 52 |
json=updated_data
|
| 53 |
)
|
|
|
|
| 54 |
if response.status_code == 200:
|
| 55 |
print("Successfully updated the dataset")
|
| 56 |
else:
|
| 57 |
-
print("Failed to update the dataset")
|
| 58 |
|
| 59 |
# Function to get bot response
|
| 60 |
def format_alpaca_prompt(state):
|
|
|
|
| 21 |
|
| 22 |
from datasets import load_dataset
|
| 23 |
import requests
|
| 24 |
+
import os
|
| 25 |
|
| 26 |
def get_user_elo_ratings():
|
| 27 |
dataset = load_dataset("rwitz/mistral-elo-ratings", streaming=True)
|
| 28 |
elo_ratings = dataset['train'] # or the relevant split
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
return elo_ratings
|
| 30 |
|
| 31 |
def update_elo_rating(player_id, new_rating):
|
| 32 |
# Fetch the current dataset
|
| 33 |
elo_ratings = get_user_elo_ratings()
|
| 34 |
|
| 35 |
+
# Function to update the rating of a specific player
|
| 36 |
+
def update_rating(example):
|
| 37 |
+
return {'rating': new_rating}
|
| 38 |
+
|
| 39 |
+
# Update the dataset
|
| 40 |
+
updated_dataset = elo_ratings.map(update_rating)
|
| 41 |
+
|
| 42 |
+
# Convert updated dataset to a dictionary for pushing
|
| 43 |
+
updated_data = updated_dataset.to_dict()
|
| 44 |
|
| 45 |
# Push the updated dataset back to Hugging Face
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
response = requests.post(
|
| 47 |
"https://huggingface.co/datasets/rwitz/mistral-elo-ratings",
|
| 48 |
+
headers={"Authorization": f"Bearer {os.environ.get('HUGGINGFACE_TOKEN')}"},
|
| 49 |
json=updated_data
|
| 50 |
)
|
| 51 |
+
|
| 52 |
if response.status_code == 200:
|
| 53 |
print("Successfully updated the dataset")
|
| 54 |
else:
|
| 55 |
+
print("Failed to update the dataset. Response code:", response.status_code)
|
| 56 |
|
| 57 |
# Function to get bot response
|
| 58 |
def format_alpaca_prompt(state):
|