Change to dataset, remove upload_file
Browse files- app.py +31 -45
- src/submission/submit.py +10 -31
app.py
CHANGED
@@ -7,6 +7,7 @@ import os
|
|
7 |
import logging
|
8 |
import json
|
9 |
from datetime import datetime
|
|
|
10 |
|
11 |
from src.core.evaluation import EvaluationManager, EvaluationRequest
|
12 |
from src.logging_config import setup_logging
|
@@ -111,15 +112,15 @@ def update_leaderboard():
|
|
111 |
def process_evaluation_queue():
|
112 |
"""Process pending evaluation requests."""
|
113 |
logger.info("Processing evaluation queue")
|
114 |
-
|
115 |
# Fetch pending requests from Hugging Face repository
|
116 |
_, _, pending_requests = get_evaluation_queue_df(EVAL_COLS + ['model_raw'])
|
117 |
-
|
118 |
for _, request in pending_requests.iterrows():
|
119 |
try:
|
120 |
model_name = request['model_raw']
|
121 |
logger.info(f"Processing request for model: {model_name}")
|
122 |
-
|
123 |
# Convert queue request to evaluation request
|
124 |
eval_request = EvaluationRequest(
|
125 |
model=model_name,
|
@@ -153,23 +154,21 @@ def update_request_status(model_name, status):
|
|
153 |
try:
|
154 |
api = HfApi()
|
155 |
filename = f"{model_name.replace('/', '_')}_request.json"
|
156 |
-
|
157 |
# Fetch the current request data
|
158 |
file_content = api.hf_hub_download(repo_id=QUEUE_REPO, filename=filename, repo_type="dataset")
|
159 |
with open(file_content, 'r') as f:
|
160 |
request_data = json.load(f)
|
161 |
-
|
162 |
# Update the status
|
163 |
request_data['status'] = status
|
164 |
-
|
165 |
-
#
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
token=TOKEN
|
172 |
-
)
|
173 |
logger.info(f"Updated status for {model_name} to {status}")
|
174 |
except Exception as e:
|
175 |
logger.error(f"Failed to update status for {model_name}: {str(e)}", exc_info=True)
|
@@ -181,25 +180,17 @@ from huggingface_hub import HfApi
|
|
181 |
def save_results_to_repo(results, repo):
|
182 |
"""Save evaluation results to the specified repository."""
|
183 |
try:
|
184 |
-
api = HfApi()
|
185 |
model_id = results.get('model', '').replace('/', '_')
|
186 |
if not model_id:
|
187 |
raise ValueError("Model ID not found in results")
|
188 |
-
filename = f"{model_id}_results.json"
|
189 |
|
190 |
-
#
|
191 |
-
|
192 |
|
193 |
-
#
|
194 |
-
|
195 |
-
path_or_fileobj=json_results.encode(),
|
196 |
-
path_in_repo=filename,
|
197 |
-
repo_id=repo,
|
198 |
-
repo_type="dataset",
|
199 |
-
token=TOKEN
|
200 |
-
)
|
201 |
|
202 |
-
logger.info(f"Saved results for {model_id} to {repo}
|
203 |
except Exception as e:
|
204 |
logger.error(f"Failed to save results to {repo}: {str(e)}", exc_info=True)
|
205 |
|
@@ -230,7 +221,7 @@ def init_leaderboard(df):
|
|
230 |
"safetensors_compliant": "Safetensors",
|
231 |
"precision": "Precision"
|
232 |
}
|
233 |
-
|
234 |
for src, dst in column_mapping.items():
|
235 |
if src in df.columns:
|
236 |
df[dst] = df[src]
|
@@ -376,7 +367,7 @@ with demo:
|
|
376 |
"""Handle new model submission."""
|
377 |
try:
|
378 |
logger.info(f"New submission received for {model}")
|
379 |
-
|
380 |
# Prepare request data
|
381 |
request_data = {
|
382 |
"model": model,
|
@@ -388,31 +379,26 @@ with demo:
|
|
388 |
"status": "PENDING",
|
389 |
"timestamp": datetime.now().isoformat()
|
390 |
}
|
391 |
-
|
392 |
-
#
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
repo_id=QUEUE_REPO,
|
399 |
-
repo_type="dataset",
|
400 |
-
token=TOKEN
|
401 |
-
)
|
402 |
-
|
403 |
logger.info(f"Added request for {model} to {QUEUE_REPO}")
|
404 |
-
|
405 |
# Get updated pending evaluations
|
406 |
_, _, pending_eval_queue_df = get_evaluation_queue_df(EVAL_COLS)
|
407 |
-
|
408 |
# Start processing queue in background
|
409 |
scheduler.add_job(process_evaluation_queue, id='process_queue_job', replace_existing=True)
|
410 |
-
|
411 |
return gr.Markdown("Submission successful! Your model has been added to the evaluation queue. Please check the 'Pending Evaluation Queue' for status updates."), pending_eval_queue_df
|
412 |
except Exception as e:
|
413 |
logger.error(f"Submission failed: {str(e)}", exc_info=True)
|
414 |
return gr.Markdown(f"Error: {str(e)}"), None
|
415 |
-
|
416 |
# Remove the queue_manager initialization
|
417 |
# queue_manager = QueueManager(queue_dir=os.path.join(CACHE_PATH, "eval-queue"))
|
418 |
|
|
|
7 |
import logging
|
8 |
import json
|
9 |
from datetime import datetime
|
10 |
+
from datasets import Dataset
|
11 |
|
12 |
from src.core.evaluation import EvaluationManager, EvaluationRequest
|
13 |
from src.logging_config import setup_logging
|
|
|
112 |
def process_evaluation_queue():
|
113 |
"""Process pending evaluation requests."""
|
114 |
logger.info("Processing evaluation queue")
|
115 |
+
|
116 |
# Fetch pending requests from Hugging Face repository
|
117 |
_, _, pending_requests = get_evaluation_queue_df(EVAL_COLS + ['model_raw'])
|
118 |
+
|
119 |
for _, request in pending_requests.iterrows():
|
120 |
try:
|
121 |
model_name = request['model_raw']
|
122 |
logger.info(f"Processing request for model: {model_name}")
|
123 |
+
|
124 |
# Convert queue request to evaluation request
|
125 |
eval_request = EvaluationRequest(
|
126 |
model=model_name,
|
|
|
154 |
try:
|
155 |
api = HfApi()
|
156 |
filename = f"{model_name.replace('/', '_')}_request.json"
|
157 |
+
|
158 |
# Fetch the current request data
|
159 |
file_content = api.hf_hub_download(repo_id=QUEUE_REPO, filename=filename, repo_type="dataset")
|
160 |
with open(file_content, 'r') as f:
|
161 |
request_data = json.load(f)
|
162 |
+
|
163 |
# Update the status
|
164 |
request_data['status'] = status
|
165 |
+
|
166 |
+
# Create a Dataset object from the updated request data
|
167 |
+
dataset = Dataset.from_dict(request_data)
|
168 |
+
|
169 |
+
# Push the updated dataset to the Hugging Face Hub
|
170 |
+
dataset.push_to_hub(QUEUE_REPO)
|
171 |
+
|
|
|
|
|
172 |
logger.info(f"Updated status for {model_name} to {status}")
|
173 |
except Exception as e:
|
174 |
logger.error(f"Failed to update status for {model_name}: {str(e)}", exc_info=True)
|
|
|
180 |
def save_results_to_repo(results, repo):
|
181 |
"""Save evaluation results to the specified repository."""
|
182 |
try:
|
|
|
183 |
model_id = results.get('model', '').replace('/', '_')
|
184 |
if not model_id:
|
185 |
raise ValueError("Model ID not found in results")
|
|
|
186 |
|
187 |
+
# Create a Dataset object from the results
|
188 |
+
dataset = Dataset.from_dict(results)
|
189 |
|
190 |
+
# Push the dataset to the Hugging Face Hub
|
191 |
+
dataset.push_to_hub(repo)
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
|
193 |
+
logger.info(f"Saved results for {model_id} to {repo}")
|
194 |
except Exception as e:
|
195 |
logger.error(f"Failed to save results to {repo}: {str(e)}", exc_info=True)
|
196 |
|
|
|
221 |
"safetensors_compliant": "Safetensors",
|
222 |
"precision": "Precision"
|
223 |
}
|
224 |
+
|
225 |
for src, dst in column_mapping.items():
|
226 |
if src in df.columns:
|
227 |
df[dst] = df[src]
|
|
|
367 |
"""Handle new model submission."""
|
368 |
try:
|
369 |
logger.info(f"New submission received for {model}")
|
370 |
+
|
371 |
# Prepare request data
|
372 |
request_data = {
|
373 |
"model": model,
|
|
|
379 |
"status": "PENDING",
|
380 |
"timestamp": datetime.now().isoformat()
|
381 |
}
|
382 |
+
|
383 |
+
# Convert request data to a Dataset
|
384 |
+
dataset = Dataset.from_dict(request_data)
|
385 |
+
|
386 |
+
# Push the dataset to the Hugging Face Hub
|
387 |
+
dataset.push_to_hub(QUEUE_REPO)
|
388 |
+
|
|
|
|
|
|
|
|
|
|
|
389 |
logger.info(f"Added request for {model} to {QUEUE_REPO}")
|
390 |
+
|
391 |
# Get updated pending evaluations
|
392 |
_, _, pending_eval_queue_df = get_evaluation_queue_df(EVAL_COLS)
|
393 |
+
|
394 |
# Start processing queue in background
|
395 |
scheduler.add_job(process_evaluation_queue, id='process_queue_job', replace_existing=True)
|
396 |
+
|
397 |
return gr.Markdown("Submission successful! Your model has been added to the evaluation queue. Please check the 'Pending Evaluation Queue' for status updates."), pending_eval_queue_df
|
398 |
except Exception as e:
|
399 |
logger.error(f"Submission failed: {str(e)}", exc_info=True)
|
400 |
return gr.Markdown(f"Error: {str(e)}"), None
|
401 |
+
|
402 |
# Remove the queue_manager initialization
|
403 |
# queue_manager = QueueManager(queue_dir=os.path.join(CACHE_PATH, "eval-queue"))
|
404 |
|
src/submission/submit.py
CHANGED
@@ -22,6 +22,7 @@ from src.config import (
|
|
22 |
LOG_LEVEL,
|
23 |
EVALUATION_WAIT_TIME
|
24 |
)
|
|
|
25 |
|
26 |
REQUESTED_MODELS: Optional[Dict[str, Any]] = None
|
27 |
USERS_TO_SUBMISSION_DATES: Optional[Dict[str, Any]] = None
|
@@ -158,45 +159,23 @@ def add_new_eval(
|
|
158 |
|
159 |
model_size = get_model_size(model_info=model_info, precision=precision)
|
160 |
|
161 |
-
eval_entry = create_eval_entry(model, base_model, revision, precision, weight_type, model_type, model_info, model_size)
|
162 |
-
|
163 |
# Check for duplicate submission
|
164 |
if f"{model}_{revision}_{precision}" in REQUESTED_MODELS:
|
165 |
return styled_warning("This model has been already submitted.")
|
166 |
|
167 |
-
logger.info("Creating eval
|
168 |
-
|
169 |
-
os.makedirs(OUT_DIR, exist_ok=True)
|
170 |
-
out_path = os.path.join(OUT_DIR, f"{model_path}_eval_request_False_{precision}_{weight_type}.json")
|
171 |
|
172 |
-
|
173 |
-
|
174 |
-
json.dump(eval_entry, f)
|
175 |
-
except IOError as e:
|
176 |
-
logger.error(f"Failed to write eval file: {e}")
|
177 |
-
return styled_error(f"Failed to create eval file: {e}")
|
178 |
|
179 |
-
logger.info("Uploading eval
|
180 |
try:
|
181 |
-
#
|
182 |
-
|
183 |
-
|
184 |
-
API.upload_file(
|
185 |
-
path_or_fileobj=out_path,
|
186 |
-
path_in_repo=rel_path,
|
187 |
-
repo_id=QUEUE_REPO,
|
188 |
-
repo_type="dataset",
|
189 |
-
commit_message=f"Add {model} to eval queue",
|
190 |
-
)
|
191 |
except Exception as e:
|
192 |
-
logger.error(f"Failed to upload eval
|
193 |
-
return styled_error(f"Failed to upload eval
|
194 |
-
|
195 |
-
# Remove the local file
|
196 |
-
try:
|
197 |
-
os.remove(out_path)
|
198 |
-
except OSError as e:
|
199 |
-
logger.warning(f"Failed to remove local eval file: {e}")
|
200 |
|
201 |
return styled_message(
|
202 |
f"Your request has been submitted to the evaluation queue!\n"
|
|
|
22 |
LOG_LEVEL,
|
23 |
EVALUATION_WAIT_TIME
|
24 |
)
|
25 |
+
from datasets import Dataset
|
26 |
|
27 |
REQUESTED_MODELS: Optional[Dict[str, Any]] = None
|
28 |
USERS_TO_SUBMISSION_DATES: Optional[Dict[str, Any]] = None
|
|
|
159 |
|
160 |
model_size = get_model_size(model_info=model_info, precision=precision)
|
161 |
|
|
|
|
|
162 |
# Check for duplicate submission
|
163 |
if f"{model}_{revision}_{precision}" in REQUESTED_MODELS:
|
164 |
return styled_warning("This model has been already submitted.")
|
165 |
|
166 |
+
logger.info("Creating eval entry")
|
167 |
+
eval_entry = create_eval_entry(model, base_model, revision, precision, weight_type, model_type, model_info, model_size)
|
|
|
|
|
168 |
|
169 |
+
# Convert eval entry to a Dataset
|
170 |
+
dataset = Dataset.from_dict(eval_entry)
|
|
|
|
|
|
|
|
|
171 |
|
172 |
+
logger.info("Uploading eval entry")
|
173 |
try:
|
174 |
+
# Push the dataset to the Hugging Face Hub
|
175 |
+
dataset.push_to_hub(QUEUE_REPO, commit_message=f"Add {model} to eval queue")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
except Exception as e:
|
177 |
+
logger.error(f"Failed to upload eval entry: {e}")
|
178 |
+
return styled_error(f"Failed to upload eval entry: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
|
180 |
return styled_message(
|
181 |
f"Your request has been submitted to the evaluation queue!\n"
|