Spaces:
Running
Running
zhimin-z
commited on
Commit
·
75d304c
1
Parent(s):
a3a4515
refine
Browse files
app.py
CHANGED
|
@@ -316,12 +316,12 @@ def format_conversation_history(conversation_history):
|
|
| 316 |
return formatted_text
|
| 317 |
|
| 318 |
|
| 319 |
-
def save_content_to_hf(
|
| 320 |
"""
|
| 321 |
Save feedback content to Hugging Face repository.
|
| 322 |
"""
|
| 323 |
# Serialize the content to JSON and encode it as bytes
|
| 324 |
-
json_content = json.dumps(
|
| 325 |
|
| 326 |
# Create a binary file-like object
|
| 327 |
file_like_object = io.BytesIO(json_content)
|
|
@@ -366,7 +366,7 @@ def load_content_from_hf(repo_name):
|
|
| 366 |
Returns:
|
| 367 |
list: Aggregated feedback data read from the repository.
|
| 368 |
"""
|
| 369 |
-
|
| 370 |
try:
|
| 371 |
api = HfApi()
|
| 372 |
# List all files in the repository
|
|
@@ -381,8 +381,8 @@ def load_content_from_hf(repo_name):
|
|
| 381 |
with open(local_path, "r") as f:
|
| 382 |
data = json.load(f)
|
| 383 |
data["timestamp"] = file.split("/")[-1].split(".")[0]
|
| 384 |
-
|
| 385 |
-
return
|
| 386 |
|
| 387 |
except:
|
| 388 |
raise Exception("Error loading feedback data from Hugging Face repository.")
|
|
@@ -417,8 +417,8 @@ def get_leaderboard_data(vote_entry=None, use_cache=True):
|
|
| 417 |
print(f"No cached leaderboard found, computing from votes...")
|
| 418 |
|
| 419 |
# Load feedback data from the Hugging Face repository
|
| 420 |
-
|
| 421 |
-
vote_df = pd.DataFrame(
|
| 422 |
|
| 423 |
# Concatenate the new feedback with the existing leaderboard data
|
| 424 |
if vote_entry is not None:
|
|
|
|
| 316 |
return formatted_text
|
| 317 |
|
| 318 |
|
| 319 |
+
def save_content_to_hf(data, repo_name, file_name, token=None):
|
| 320 |
"""
|
| 321 |
Save feedback content to Hugging Face repository.
|
| 322 |
"""
|
| 323 |
# Serialize the content to JSON and encode it as bytes
|
| 324 |
+
json_content = json.dumps(data, indent=4).encode("utf-8")
|
| 325 |
|
| 326 |
# Create a binary file-like object
|
| 327 |
file_like_object = io.BytesIO(json_content)
|
|
|
|
| 366 |
Returns:
|
| 367 |
list: Aggregated feedback data read from the repository.
|
| 368 |
"""
|
| 369 |
+
data = []
|
| 370 |
try:
|
| 371 |
api = HfApi()
|
| 372 |
# List all files in the repository
|
|
|
|
| 381 |
with open(local_path, "r") as f:
|
| 382 |
data = json.load(f)
|
| 383 |
data["timestamp"] = file.split("/")[-1].split(".")[0]
|
| 384 |
+
data.append(data)
|
| 385 |
+
return data
|
| 386 |
|
| 387 |
except:
|
| 388 |
raise Exception("Error loading feedback data from Hugging Face repository.")
|
|
|
|
| 417 |
print(f"No cached leaderboard found, computing from votes...")
|
| 418 |
|
| 419 |
# Load feedback data from the Hugging Face repository
|
| 420 |
+
data = load_content_from_hf(VOTE_REPO)
|
| 421 |
+
vote_df = pd.DataFrame(data)
|
| 422 |
|
| 423 |
# Concatenate the new feedback with the existing leaderboard data
|
| 424 |
if vote_entry is not None:
|