lukehinds commited on
Commit
700205f
·
1 Parent(s): b833760

Conform on dataset parquet format

Browse files
Files changed (3) hide show
  1. app.py +46 -46
  2. src/core/evaluation.py +5 -2
  3. src/populate.py +20 -27
app.py CHANGED
@@ -152,23 +152,27 @@ def process_evaluation_queue():
152
  def update_request_status(model_name, status):
153
  """Update the status of a request in the Hugging Face repository."""
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,15 +184,21 @@ from huggingface_hub import HfApi
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:
@@ -368,37 +378,27 @@ with demo:
368
  try:
369
  logger.info(f"New submission received for {model}")
370
 
371
- # Prepare request data
372
  request_data = {
373
- "model": model,
374
- "base_model": base_model,
375
- "revision": revision if revision else "main",
376
- "precision": precision,
377
- "weight_type": weight_type,
378
- "model_type": model_type,
379
- "status": "PENDING",
380
- "timestamp": datetime.now().isoformat()
 
381
  }
382
 
383
- # Create a unique filename for the request
384
- filename = f"{model.replace('/', '_')}_request.json"
385
-
386
- # Save request data as JSON
387
- with open(filename, 'w') as f:
388
- json.dump(request_data, f, indent=2)
389
-
390
- # Upload the JSON file to the Hub
391
- api = HfApi()
392
- api.upload_file(
393
- path_or_fileobj=filename,
394
- path_in_repo=filename,
395
- repo_id=QUEUE_REPO,
396
- repo_type="dataset"
397
  )
398
 
399
- # Clean up local file
400
- os.remove(filename)
401
-
402
  logger.info(f"Added request for {model} to {QUEUE_REPO}")
403
 
404
  # Get updated pending evaluations
 
152
  def update_request_status(model_name, status):
153
  """Update the status of a request in the Hugging Face repository."""
154
  try:
155
+ # Load the current dataset
156
+ from datasets import load_dataset
157
+ dataset = load_dataset(QUEUE_REPO, split="train")
158
+
159
+ # Find the row for this model and update its status
160
+ data_dict = dataset.to_dict()
161
+ indices = [i for i, m in enumerate(data_dict["model"]) if m == model_name]
162
+
163
+ if not indices:
164
+ logger.error(f"No request found for model {model_name}")
165
+ return
166
+
167
+ # Update the status for the found request
168
+ data_dict["status"][indices[0]] = status
169
+
170
+ # Create new dataset with updated status
171
+ updated_dataset = Dataset.from_dict(data_dict)
172
+
173
+ # Push the updated dataset back to the hub
174
+ updated_dataset.push_to_hub(QUEUE_REPO, split="train")
175
+
176
  logger.info(f"Updated status for {model_name} to {status}")
177
  except Exception as e:
178
  logger.error(f"Failed to update status for {model_name}: {str(e)}", exc_info=True)
 
184
  def save_results_to_repo(results, repo):
185
  """Save evaluation results to the specified repository."""
186
  try:
187
+ model_id = results.get('model', '')
188
  if not model_id:
189
  raise ValueError("Model ID not found in results")
190
 
191
+ # Convert all values to lists if they aren't already
192
+ dataset_dict = {
193
+ k: [v] if not isinstance(v, list) else v
194
+ for k, v in results.items()
195
+ }
196
+
197
  # Create a Dataset object from the results
198
+ dataset = Dataset.from_dict(dataset_dict)
199
 
200
  # Push the dataset to the Hugging Face Hub
201
+ dataset.push_to_hub(repo, split="train")
202
 
203
  logger.info(f"Saved results for {model_id} to {repo}")
204
  except Exception as e:
 
378
  try:
379
  logger.info(f"New submission received for {model}")
380
 
381
+ # Prepare request data as a dataset-compatible dictionary (all values must be lists)
382
  request_data = {
383
+ "model": [model],
384
+ "model_raw": [model], # Store raw model name for processing
385
+ "base_model": [base_model if base_model else ""],
386
+ "revision": [revision if revision else "main"],
387
+ "precision": [precision],
388
+ "weight_type": [weight_type],
389
+ "model_type": [model_type],
390
+ "status": ["PENDING"],
391
+ "timestamp": [datetime.now().isoformat()]
392
  }
393
 
394
+ # Convert to dataset and push to hub
395
+ dataset = Dataset.from_dict(request_data)
396
+ dataset.push_to_hub(
397
+ QUEUE_REPO,
398
+ config_name=model.replace("/", "_"),
399
+ split="train"
 
 
 
 
 
 
 
 
400
  )
401
 
 
 
 
402
  logger.info(f"Added request for {model} to {QUEUE_REPO}")
403
 
404
  # Get updated pending evaluations
src/core/evaluation.py CHANGED
@@ -108,17 +108,20 @@ class EvaluationManager:
108
  "model_type": request.model_type,
109
  }
110
 
 
 
 
111
  # Save and backup results
112
  eval_id = f"{request.model.replace('/', '_')}_{request.revision}"
113
  result_path = os.path.join(self.results_dir, f"{eval_id}.json")
114
 
115
  with open(result_path, 'w') as f:
116
- json.dump(results, f, indent=2)
117
 
118
  self.backup_results(eval_id)
119
  logger.info(f"Evaluation complete for {request.model}")
120
 
121
- return results
122
 
123
  except Exception as e:
124
  logger.error(f"Evaluation failed: {str(e)}", exc_info=True)
 
108
  "model_type": request.model_type,
109
  }
110
 
111
+ # Convert results to dataset-compatible format (lists)
112
+ dataset_results = {k: [v] for k, v in results.items()}
113
+
114
  # Save and backup results
115
  eval_id = f"{request.model.replace('/', '_')}_{request.revision}"
116
  result_path = os.path.join(self.results_dir, f"{eval_id}.json")
117
 
118
  with open(result_path, 'w') as f:
119
+ json.dump(dataset_results, f, indent=2)
120
 
121
  self.backup_results(eval_id)
122
  logger.info(f"Evaluation complete for {request.model}")
123
 
124
+ return dataset_results
125
 
126
  except Exception as e:
127
  logger.error(f"Evaluation failed: {str(e)}", exc_info=True)
src/populate.py CHANGED
@@ -102,34 +102,27 @@ def get_evaluation_queue_df(cols: list) -> list[pd.DataFrame]:
102
  logger.info(f"Looking for eval requests in {QUEUE_REPO}")
103
  all_evals = []
104
 
105
- api = HfApi()
106
-
107
  try:
108
- # List all files in the repository
109
- files = api.list_repo_files(repo_id=QUEUE_REPO, repo_type="dataset")
110
-
111
- # Filter for JSON files
112
- json_files = [f for f in files if f.endswith('.json')]
113
-
114
- for file in json_files:
115
- try:
116
- # Download and read each JSON file
117
- content = api.hf_hub_download(repo_id=QUEUE_REPO, filename=file, repo_type="dataset")
118
- logger.info(f"Reading JSON file: {file}")
119
- with open(content, 'r') as fp:
120
- data = json.load(fp)
121
-
122
- # Check if data is a list (multiple requests in one file)
123
- if isinstance(data, list):
124
- for item in data:
125
- formatted_data = format_eval_data(item)
126
- all_evals.append(formatted_data)
127
- else:
128
- # Single request in the file
129
- formatted_data = format_eval_data(data)
130
- all_evals.append(formatted_data)
131
- except Exception as e:
132
- logger.error(f"Error processing file {file}: {str(e)}", exc_info=True)
133
 
134
  except Exception as e:
135
  logger.error(f"Error fetching requests from {QUEUE_REPO}: {str(e)}", exc_info=True)
 
102
  logger.info(f"Looking for eval requests in {QUEUE_REPO}")
103
  all_evals = []
104
 
 
 
105
  try:
106
+ # Load the dataset directly
107
+ from datasets import load_dataset
108
+ dataset = load_dataset(QUEUE_REPO, split="train")
109
+ logger.debug(f"Loaded dataset with {len(dataset)} rows")
110
+ logger.debug(f"Dataset features: {dataset.features}")
111
+
112
+ # Convert dataset to list of dicts
113
+ for row in dataset:
114
+ formatted_data = format_eval_data({
115
+ "model": row["model"],
116
+ "model_raw": row.get("model_raw", row["model"]), # Fallback to model if model_raw not present
117
+ "base_model": row.get("base_model", ""),
118
+ "revision": row.get("revision", "main"),
119
+ "precision": row.get("precision", ""),
120
+ "weight_type": row.get("weight_type", ""),
121
+ "model_type": row.get("model_type", ""),
122
+ "status": row.get("status", "PENDING"),
123
+ "timestamp": row.get("timestamp", "")
124
+ })
125
+ all_evals.append(formatted_data)
 
 
 
 
 
126
 
127
  except Exception as e:
128
  logger.error(f"Error fetching requests from {QUEUE_REPO}: {str(e)}", exc_info=True)