Update app.py
Browse files
app.py
CHANGED
|
@@ -162,7 +162,6 @@
|
|
| 162 |
|
| 163 |
# demo.launch()
|
| 164 |
|
| 165 |
-
|
| 166 |
import gradio as gr
|
| 167 |
import pandas as pd
|
| 168 |
import re
|
|
@@ -173,38 +172,42 @@ import os
|
|
| 173 |
|
| 174 |
# Constants for Hugging Face repositories
|
| 175 |
HF_TOKEN = os.getenv("HF_TOKEN") # Hugging Face token stored as an environment variable
|
|
|
|
|
|
|
|
|
|
| 176 |
LEADERBOARD_REPO = "SondosMB/leaderboard-dataset" # Replace with your leaderboard dataset name
|
| 177 |
GROUND_TRUTH_REPO = "SondosMB/ground-truth-dataset" # Replace with your ground truth dataset name
|
| 178 |
LAST_UPDATED = datetime.now().strftime("%B %d, %Y")
|
| 179 |
|
| 180 |
def load_ground_truth():
|
| 181 |
"""
|
| 182 |
-
Load the ground truth file from a
|
| 183 |
"""
|
| 184 |
try:
|
| 185 |
-
print("
|
| 186 |
ground_truth_path = hf_hub_download(
|
| 187 |
repo_id=GROUND_TRUTH_REPO,
|
| 188 |
filename="ground_truth.csv",
|
| 189 |
use_auth_token=HF_TOKEN
|
| 190 |
)
|
| 191 |
-
print(f"Ground truth file downloaded
|
| 192 |
return pd.read_csv(ground_truth_path)
|
| 193 |
except Exception as e:
|
| 194 |
-
print(f"Error loading ground truth: {e}")
|
| 195 |
return None
|
| 196 |
|
| 197 |
-
|
| 198 |
def load_leaderboard():
|
| 199 |
"""
|
| 200 |
-
Load the leaderboard from a
|
| 201 |
"""
|
| 202 |
try:
|
|
|
|
| 203 |
leaderboard_path = hf_hub_download(
|
| 204 |
repo_id=LEADERBOARD_REPO,
|
| 205 |
filename="leaderboard.csv",
|
| 206 |
use_auth_token=HF_TOKEN
|
| 207 |
)
|
|
|
|
| 208 |
return pd.read_csv(leaderboard_path)
|
| 209 |
except Exception as e:
|
| 210 |
print(f"Error loading leaderboard: {e}")
|
|
@@ -219,7 +222,7 @@ def load_leaderboard():
|
|
| 219 |
|
| 220 |
def update_leaderboard(results):
|
| 221 |
"""
|
| 222 |
-
Append new submission results to the
|
| 223 |
"""
|
| 224 |
try:
|
| 225 |
# Load existing leaderboard or create a new one
|
|
@@ -229,7 +232,8 @@ def update_leaderboard(results):
|
|
| 229 |
use_auth_token=HF_TOKEN
|
| 230 |
)
|
| 231 |
df = pd.read_csv(leaderboard_path)
|
| 232 |
-
except:
|
|
|
|
| 233 |
df = pd.DataFrame(columns=[
|
| 234 |
"Model Name", "Overall Accuracy", "Valid Accuracy",
|
| 235 |
"Correct Predictions", "Total Questions", "Timestamp"
|
|
@@ -308,7 +312,7 @@ def evaluate_predictions(prediction_file, model_name, add_to_leaderboard):
|
|
| 308 |
|
| 309 |
# Gradio Interface
|
| 310 |
with gr.Blocks() as demo:
|
| 311 |
-
gr.Markdown("# Secure Prediction Evaluation Tool with
|
| 312 |
|
| 313 |
with gr.Tabs():
|
| 314 |
# Submission Tab
|
|
@@ -350,3 +354,4 @@ with gr.Blocks() as demo:
|
|
| 350 |
demo.launch()
|
| 351 |
|
| 352 |
|
|
|
|
|
|
| 162 |
|
| 163 |
# demo.launch()
|
| 164 |
|
|
|
|
| 165 |
import gradio as gr
|
| 166 |
import pandas as pd
|
| 167 |
import re
|
|
|
|
| 172 |
|
| 173 |
# Constants for Hugging Face repositories
|
| 174 |
HF_TOKEN = os.getenv("HF_TOKEN") # Hugging Face token stored as an environment variable
|
| 175 |
+
if not HF_TOKEN:
|
| 176 |
+
raise ValueError("HF_TOKEN is not set. Please add it as a secret in your Hugging Face Space.")
|
| 177 |
+
|
| 178 |
LEADERBOARD_REPO = "SondosMB/leaderboard-dataset" # Replace with your leaderboard dataset name
|
| 179 |
GROUND_TRUTH_REPO = "SondosMB/ground-truth-dataset" # Replace with your ground truth dataset name
|
| 180 |
LAST_UPDATED = datetime.now().strftime("%B %d, %Y")
|
| 181 |
|
| 182 |
def load_ground_truth():
|
| 183 |
"""
|
| 184 |
+
Load the ground truth file from a gated Hugging Face dataset.
|
| 185 |
"""
|
| 186 |
try:
|
| 187 |
+
print("Fetching ground truth file...")
|
| 188 |
ground_truth_path = hf_hub_download(
|
| 189 |
repo_id=GROUND_TRUTH_REPO,
|
| 190 |
filename="ground_truth.csv",
|
| 191 |
use_auth_token=HF_TOKEN
|
| 192 |
)
|
| 193 |
+
print(f"Ground truth file downloaded: {ground_truth_path}")
|
| 194 |
return pd.read_csv(ground_truth_path)
|
| 195 |
except Exception as e:
|
| 196 |
+
print(f"Error loading ground truth file: {e}")
|
| 197 |
return None
|
| 198 |
|
|
|
|
| 199 |
def load_leaderboard():
|
| 200 |
"""
|
| 201 |
+
Load the leaderboard from a gated Hugging Face dataset.
|
| 202 |
"""
|
| 203 |
try:
|
| 204 |
+
print("Fetching leaderboard file...")
|
| 205 |
leaderboard_path = hf_hub_download(
|
| 206 |
repo_id=LEADERBOARD_REPO,
|
| 207 |
filename="leaderboard.csv",
|
| 208 |
use_auth_token=HF_TOKEN
|
| 209 |
)
|
| 210 |
+
print(f"Leaderboard file downloaded: {leaderboard_path}")
|
| 211 |
return pd.read_csv(leaderboard_path)
|
| 212 |
except Exception as e:
|
| 213 |
print(f"Error loading leaderboard: {e}")
|
|
|
|
| 222 |
|
| 223 |
def update_leaderboard(results):
|
| 224 |
"""
|
| 225 |
+
Append new submission results to the gated leaderboard dataset.
|
| 226 |
"""
|
| 227 |
try:
|
| 228 |
# Load existing leaderboard or create a new one
|
|
|
|
| 232 |
use_auth_token=HF_TOKEN
|
| 233 |
)
|
| 234 |
df = pd.read_csv(leaderboard_path)
|
| 235 |
+
except Exception as e:
|
| 236 |
+
print(f"Error loading leaderboard: {e}")
|
| 237 |
df = pd.DataFrame(columns=[
|
| 238 |
"Model Name", "Overall Accuracy", "Valid Accuracy",
|
| 239 |
"Correct Predictions", "Total Questions", "Timestamp"
|
|
|
|
| 312 |
|
| 313 |
# Gradio Interface
|
| 314 |
with gr.Blocks() as demo:
|
| 315 |
+
gr.Markdown("# Secure Prediction Evaluation Tool with Gated Leaderboard")
|
| 316 |
|
| 317 |
with gr.Tabs():
|
| 318 |
# Submission Tab
|
|
|
|
| 354 |
demo.launch()
|
| 355 |
|
| 356 |
|
| 357 |
+
|