akera commited on
Commit
745019f
Β·
verified Β·
1 Parent(s): 57c7739

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -21
app.py CHANGED
@@ -1,7 +1,4 @@
1
  # app.py
2
-
3
- # app.py (add this at the very top)
4
-
5
  import subprocess
6
  import sys
7
  import os
@@ -163,39 +160,49 @@ def download_test_set() -> Tuple[str, str]:
163
  return None, error_msg
164
 
165
  def validate_submission(file, model_name: str, author: str, description: str) -> Tuple[str, Optional[pd.DataFrame]]:
166
- """Validate uploaded prediction file."""
167
-
168
  try:
169
  if file is None:
170
  return "❌ Please upload a predictions file", None
171
-
172
  if not model_name.strip():
173
  return "❌ Please provide a model name", None
174
-
175
- # Read file content
176
- file_content = file.read()
177
- filename = file.name
178
-
179
- # Get test set for validation
 
 
 
 
 
 
 
 
 
180
  global complete_test_set
181
  if complete_test_set is None:
182
  complete_test_set = get_complete_test_set()
183
-
184
- # Validate submission
185
  validation_result = validate_submission_complete(
186
  file_content, filename, complete_test_set, model_name
187
  )
188
-
189
- if validation_result['valid']:
190
- # Store validation info for later use
191
- return validation_result['report'], validation_result['predictions']
192
  else:
193
- return validation_result['report'], None
194
-
195
  except Exception as e:
196
- error_msg = f"❌ Validation error: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
 
 
 
197
  return error_msg, None
198
 
 
199
  def evaluate_submission(
200
  predictions_df: pd.DataFrame,
201
  model_name: str,
 
1
  # app.py
 
 
 
2
  import subprocess
3
  import sys
4
  import os
 
160
  return None, error_msg
161
 
162
  def validate_submission(file, model_name: str, author: str, description: str) -> Tuple[str, Optional[pd.DataFrame]]:
163
+ """Validate uploaded prediction file, handling both file-like and NamedString inputs."""
 
164
  try:
165
  if file is None:
166
  return "❌ Please upload a predictions file", None
 
167
  if not model_name.strip():
168
  return "❌ Please provide a model name", None
169
+
170
+ # Read raw bytes from the upload
171
+ try:
172
+ file_content = file.read()
173
+ except AttributeError:
174
+ # Fallback for Gradio NamedString
175
+ data = getattr(file, "data", None) or getattr(file, "value", None)
176
+ if data is None:
177
+ return "❌ Could not read uploaded file", None
178
+ file_content = data.encode("utf-8") if isinstance(data, str) else data
179
+
180
+ # Determine filename
181
+ filename = getattr(file, "name", None) or getattr(file, "filename", None) or "uploaded_file"
182
+
183
+ # Load complete test set
184
  global complete_test_set
185
  if complete_test_set is None:
186
  complete_test_set = get_complete_test_set()
187
+
188
+ # Run validation
189
  validation_result = validate_submission_complete(
190
  file_content, filename, complete_test_set, model_name
191
  )
192
+
193
+ if validation_result["valid"]:
194
+ return validation_result["report"], validation_result["predictions"]
 
195
  else:
196
+ return validation_result["report"], None
197
+
198
  except Exception as e:
199
+ error_msg = (
200
+ f"❌ Validation error: {str(e)}\n\nTraceback:\n"
201
+ + traceback.format_exc()
202
+ )
203
  return error_msg, None
204
 
205
+
206
  def evaluate_submission(
207
  predictions_df: pd.DataFrame,
208
  model_name: str,