Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -159,33 +159,45 @@ def download_test_set() -> Tuple[str, str]:
|
|
159 |
error_msg = f"β Error creating test set download: {str(e)}"
|
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,
|
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 |
-
#
|
171 |
-
|
172 |
-
file_content = file
|
173 |
-
|
174 |
-
#
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
|
180 |
-
#
|
181 |
-
filename =
|
|
|
|
|
|
|
|
|
182 |
|
183 |
-
# Load
|
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 |
)
|
@@ -196,11 +208,11 @@ def validate_submission(file, model_name: str, author: str, description: str) ->
|
|
196 |
return validation_result["report"], None
|
197 |
|
198 |
except Exception as e:
|
199 |
-
|
200 |
-
f"β Validation error: {
|
201 |
-
|
202 |
)
|
203 |
-
|
204 |
|
205 |
|
206 |
def evaluate_submission(
|
|
|
159 |
error_msg = f"β Error creating test set download: {str(e)}"
|
160 |
return None, error_msg
|
161 |
|
162 |
+
|
163 |
def validate_submission(file, model_name: str, author: str, description: str) -> Tuple[str, Optional[pd.DataFrame]]:
|
164 |
+
"""Validate uploaded prediction file, supporting str paths, bytes, and Gradio wrappers."""
|
165 |
try:
|
166 |
if file is None:
|
167 |
return "β Please upload a predictions file", None
|
168 |
if not model_name.strip():
|
169 |
return "β Please provide a model name", None
|
170 |
|
171 |
+
# 1) Determine raw bytes
|
172 |
+
if isinstance(file, bytes):
|
173 |
+
file_content = file
|
174 |
+
elif isinstance(file, str):
|
175 |
+
# could be a path or raw text
|
176 |
+
if os.path.exists(file):
|
177 |
+
with open(file, "rb") as f:
|
178 |
+
file_content = f.read()
|
179 |
+
else:
|
180 |
+
file_content = file.encode("utf-8")
|
181 |
+
elif hasattr(file, "name") and os.path.exists(file.name):
|
182 |
+
# tempfile._TemporaryFileWrapper from Gradio
|
183 |
+
with open(file.name, "rb") as f:
|
184 |
+
file_content = f.read()
|
185 |
+
else:
|
186 |
+
return "β Could not read uploaded file", None
|
187 |
|
188 |
+
# 2) Infer filename for format-sniffing
|
189 |
+
filename = (
|
190 |
+
getattr(file, "name", None)
|
191 |
+
or getattr(file, "filename", None)
|
192 |
+
or "predictions.csv"
|
193 |
+
)
|
194 |
|
195 |
+
# 3) Load test set if needed
|
196 |
global complete_test_set
|
197 |
if complete_test_set is None:
|
198 |
complete_test_set = get_complete_test_set()
|
199 |
|
200 |
+
# 4) Run existing validation pipeline
|
201 |
validation_result = validate_submission_complete(
|
202 |
file_content, filename, complete_test_set, model_name
|
203 |
)
|
|
|
208 |
return validation_result["report"], None
|
209 |
|
210 |
except Exception as e:
|
211 |
+
return (
|
212 |
+
f"β Validation error: {e}\n\nTraceback:\n{traceback.format_exc()}",
|
213 |
+
None,
|
214 |
)
|
215 |
+
|
216 |
|
217 |
|
218 |
def evaluate_submission(
|