Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
fix
Browse files
app.py
CHANGED
|
@@ -25,6 +25,7 @@ from tabulate import tabulate
|
|
| 25 |
from requests import HTTPError
|
| 26 |
from gradio_client import Client
|
| 27 |
from discord import Color, Embed
|
|
|
|
| 28 |
from discord.ui import Button, View
|
| 29 |
from discord.ext import commands, tasks
|
| 30 |
from datetime import datetime, timedelta
|
|
@@ -152,17 +153,22 @@ def update_google_sheet():
|
|
| 152 |
# starting to migrate away from google sheets and towards HF datasets
|
| 153 |
def update_hf_dataset(df, repo_id="discord-community/levelbot-data", filename="levelbot-data.csv"):
|
| 154 |
try:
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
except Exception as e:
|
| 165 |
-
print(f"update_hf_dataset Error: {e}")
|
| 166 |
|
| 167 |
|
| 168 |
#@tasks.loop(minutes=1) tasks.loop leads to heartbeat blocked issues (merging calculations too much with normal discord bot functions)
|
|
|
|
| 25 |
from requests import HTTPError
|
| 26 |
from gradio_client import Client
|
| 27 |
from discord import Color, Embed
|
| 28 |
+
from huggingface_hub import HfApi
|
| 29 |
from discord.ui import Button, View
|
| 30 |
from discord.ext import commands, tasks
|
| 31 |
from datetime import datetime, timedelta
|
|
|
|
| 153 |
# starting to migrate away from google sheets and towards HF datasets
|
| 154 |
def update_hf_dataset(df, repo_id="discord-community/levelbot-data", filename="levelbot-data.csv"):
|
| 155 |
try:
|
| 156 |
+
hf_token = os.environ.get("HF_TOKEN")
|
| 157 |
+
api = HfApi(token=hf_token)
|
| 158 |
+
|
| 159 |
+
with tempfile.NamedTemporaryFile(mode='w', suffix=".csv", delete=False) as tmp:
|
| 160 |
+
df.to_csv(tmp.name, index=False)
|
| 161 |
+
api.upload_file(
|
| 162 |
+
path_or_fileobj=tmp.name,
|
| 163 |
+
path_in_repo=filename,
|
| 164 |
+
repo_id=repo_id,
|
| 165 |
+
repo_type="dataset",
|
| 166 |
+
token=hf_token,
|
| 167 |
+
commit_message="Update leaderboard CSV"
|
| 168 |
+
)
|
| 169 |
+
print(f"✅ Hugging Face dataset `{repo_id}/{filename}` updated successfully.")
|
| 170 |
except Exception as e:
|
| 171 |
+
print(f"❌ update_hf_dataset Error: {e}")
|
| 172 |
|
| 173 |
|
| 174 |
#@tasks.loop(minutes=1) tasks.loop leads to heartbeat blocked issues (merging calculations too much with normal discord bot functions)
|