Spaces:
Running on CPU Upgrade

lunarflu HF Staff commited on
Commit
fc1881a
·
verified ·
1 Parent(s): 39a3bfb
Files changed (1) hide show
  1. app.py +16 -10
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
- with tempfile.TemporaryDirectory() as tempdir:
156
- file_path = os.path.join(tempdir, filename)
157
- df.to_csv(file_path, index=False)
158
-
159
- repo = Repository(local_dir=tempdir, clone_from=repo_id, use_auth_token=hf_token)
160
- repo.git_add()
161
- repo.git_commit("Update leaderboard CSV")
162
- repo.git_push()
163
- print(f"Hugging Face dataset {repo_id}/{filename} updated successfully.")
 
 
 
 
 
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)