Spaces:
Running
Running
🐛 Fix nbr parameter type issue when submitting new models
Browse files- backend/api.py +4 -4
- backend/schema.py +4 -4
- backend/submission.py +1 -1
- frontend/leaderboard.py +40 -0
- frontend/submission.py +9 -3
backend/api.py
CHANGED
|
@@ -20,7 +20,7 @@ async def submit_model(
|
|
| 20 |
hf_space_tag: str,
|
| 21 |
model_description: str,
|
| 22 |
organization: str,
|
| 23 |
-
model_size: str
|
| 24 |
publication_title: str,
|
| 25 |
publication_link: str,
|
| 26 |
|
|
@@ -31,12 +31,12 @@ async def submit_model(
|
|
| 31 |
n_shot: str,
|
| 32 |
) -> Dict[str, Any]:
|
| 33 |
"""API endpoint for model submission with rate limiting."""
|
| 34 |
-
|
| 35 |
# Check rate limit
|
| 36 |
if not check_submission_limit(hf_space_tag):
|
| 37 |
status = get_submission_status(hf_space_tag)
|
| 38 |
raise Exception(f"Daily submission limit exceeded. Used {status['submissions_today']}/{status['daily_limit']} submissions today. Try again tomorrow.")
|
| 39 |
-
|
| 40 |
# Get test smiles and labels
|
| 41 |
test_smiles, test_labels = load_test_dataset()
|
| 42 |
|
|
@@ -46,7 +46,7 @@ async def submit_model(
|
|
| 46 |
hf_space_tag=hf_space_tag,
|
| 47 |
model_description=model_description,
|
| 48 |
organization=organization or "",
|
| 49 |
-
model_size=model_size
|
| 50 |
publication_title=publication_title or "",
|
| 51 |
publication_link=publication_link or "",
|
| 52 |
|
|
|
|
| 20 |
hf_space_tag: str,
|
| 21 |
model_description: str,
|
| 22 |
organization: str,
|
| 23 |
+
model_size: int, # Changed from str to int
|
| 24 |
publication_title: str,
|
| 25 |
publication_link: str,
|
| 26 |
|
|
|
|
| 31 |
n_shot: str,
|
| 32 |
) -> Dict[str, Any]:
|
| 33 |
"""API endpoint for model submission with rate limiting."""
|
| 34 |
+
|
| 35 |
# Check rate limit
|
| 36 |
if not check_submission_limit(hf_space_tag):
|
| 37 |
status = get_submission_status(hf_space_tag)
|
| 38 |
raise Exception(f"Daily submission limit exceeded. Used {status['submissions_today']}/{status['daily_limit']} submissions today. Try again tomorrow.")
|
| 39 |
+
|
| 40 |
# Get test smiles and labels
|
| 41 |
test_smiles, test_labels = load_test_dataset()
|
| 42 |
|
|
|
|
| 46 |
hf_space_tag=hf_space_tag,
|
| 47 |
model_description=model_description,
|
| 48 |
organization=organization or "",
|
| 49 |
+
model_size=model_size, # Now numeric
|
| 50 |
publication_title=publication_title or "",
|
| 51 |
publication_link=publication_link or "",
|
| 52 |
|
backend/schema.py
CHANGED
|
@@ -7,7 +7,7 @@ def create_submission_record(
|
|
| 7 |
hf_space_tag: str,
|
| 8 |
model_description: str,
|
| 9 |
organization: str,
|
| 10 |
-
model_size: str
|
| 11 |
publication_title: str,
|
| 12 |
publication_link: str,
|
| 13 |
|
|
@@ -52,15 +52,15 @@ def create_submission_record(
|
|
| 52 |
|
| 53 |
def get_dataset_schema() -> Dict[str, Any]:
|
| 54 |
"""Return the HuggingFace dataset schema."""
|
| 55 |
-
|
| 56 |
return {
|
| 57 |
"config": {
|
| 58 |
"model_name": "string",
|
| 59 |
-
"hf_space_tag": "string",
|
| 60 |
"model_description": "string",
|
| 61 |
"publication_title": "string",
|
| 62 |
"publication_link": "string",
|
| 63 |
-
"model_size": "string"
|
| 64 |
"pretraining": "string",
|
| 65 |
"organization": "string",
|
| 66 |
"date_submitted": "string",
|
|
|
|
| 7 |
hf_space_tag: str,
|
| 8 |
model_description: str,
|
| 9 |
organization: str,
|
| 10 |
+
model_size: int, # Changed from str to int
|
| 11 |
publication_title: str,
|
| 12 |
publication_link: str,
|
| 13 |
|
|
|
|
| 52 |
|
| 53 |
def get_dataset_schema() -> Dict[str, Any]:
|
| 54 |
"""Return the HuggingFace dataset schema."""
|
| 55 |
+
|
| 56 |
return {
|
| 57 |
"config": {
|
| 58 |
"model_name": "string",
|
| 59 |
+
"hf_space_tag": "string",
|
| 60 |
"model_description": "string",
|
| 61 |
"publication_title": "string",
|
| 62 |
"publication_link": "string",
|
| 63 |
+
"model_size": "int64", # Changed from "string" to "int64" for numeric values
|
| 64 |
"pretraining": "string",
|
| 65 |
"organization": "string",
|
| 66 |
"date_submitted": "string",
|
backend/submission.py
CHANGED
|
@@ -12,7 +12,7 @@ async def process_submission(
|
|
| 12 |
hf_space_tag: str,
|
| 13 |
model_description: str,
|
| 14 |
organization: str,
|
| 15 |
-
model_size: str
|
| 16 |
publication_title: str,
|
| 17 |
publication_link: str,
|
| 18 |
pretrained: bool,
|
|
|
|
| 12 |
hf_space_tag: str,
|
| 13 |
model_description: str,
|
| 14 |
organization: str,
|
| 15 |
+
model_size: int, # Changed from str to int
|
| 16 |
publication_title: str,
|
| 17 |
publication_link: str,
|
| 18 |
pretrained: bool,
|
frontend/leaderboard.py
CHANGED
|
@@ -10,6 +10,46 @@ from datetime import datetime
|
|
| 10 |
from config.leaderboard import MAX_DECIMALS, COLUMN_NAMES
|
| 11 |
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
def format_parameter_count(value):
|
| 14 |
"""Format parameter count to human-readable string (B, M, K).
|
| 15 |
|
|
|
|
| 10 |
from config.leaderboard import MAX_DECIMALS, COLUMN_NAMES
|
| 11 |
|
| 12 |
|
| 13 |
+
def parse_parameter_count(value):
|
| 14 |
+
"""Parse parameter count from various formats to raw numeric value.
|
| 15 |
+
|
| 16 |
+
Accepts:
|
| 17 |
+
- Raw numbers: 120000000, "120000000"
|
| 18 |
+
- Human-readable: "120M", "0.12B", "154K"
|
| 19 |
+
- Empty/None values
|
| 20 |
+
|
| 21 |
+
Args:
|
| 22 |
+
value: Parameter count in any supported format
|
| 23 |
+
|
| 24 |
+
Returns:
|
| 25 |
+
int: Raw parameter count, or None for empty/invalid values
|
| 26 |
+
"""
|
| 27 |
+
if pd.isna(value) or value == "" or value is None:
|
| 28 |
+
return None
|
| 29 |
+
|
| 30 |
+
# If already a number, return it
|
| 31 |
+
if isinstance(value, (int, float)):
|
| 32 |
+
return int(value)
|
| 33 |
+
|
| 34 |
+
# Convert string to number
|
| 35 |
+
value_str = str(value).strip().upper()
|
| 36 |
+
if not value_str:
|
| 37 |
+
return None
|
| 38 |
+
|
| 39 |
+
# Extract numeric part and suffix
|
| 40 |
+
import re
|
| 41 |
+
match = re.match(r'^([0-9.]+)\s*([KMBT]?)$', value_str)
|
| 42 |
+
if not match:
|
| 43 |
+
return None
|
| 44 |
+
|
| 45 |
+
num_part = float(match.group(1))
|
| 46 |
+
suffix = match.group(2)
|
| 47 |
+
|
| 48 |
+
# Apply multiplier based on suffix
|
| 49 |
+
multipliers = {'K': 1e3, 'M': 1e6, 'B': 1e9, 'T': 1e12, '': 1}
|
| 50 |
+
return int(num_part * multipliers[suffix])
|
| 51 |
+
|
| 52 |
+
|
| 53 |
def format_parameter_count(value):
|
| 54 |
"""Format parameter count to human-readable string (B, M, K).
|
| 55 |
|
frontend/submission.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import asyncio
|
| 2 |
import gradio as gr
|
| 3 |
from backend.api import submit_model
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
def handle_submission(
|
|
@@ -22,10 +23,15 @@ def handle_submission(
|
|
| 22 |
# Basic validation
|
| 23 |
if not model_name or not hf_space_tag or not model_description or not organization or not model_size or not pretrained or not publication_title or not publication_link or not zero_shot or not few_shot:
|
| 24 |
return "<div style='color: red;'>Please fill in all required fields (*)</div>"
|
| 25 |
-
|
| 26 |
if "/" not in hf_space_tag:
|
| 27 |
return "<div style='color: red;'>HuggingFace space tag should be in format 'username/space-name'</div>"
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
# Process submission
|
| 30 |
try:
|
| 31 |
result = asyncio.run(submit_model(
|
|
@@ -33,7 +39,7 @@ def handle_submission(
|
|
| 33 |
hf_space_tag=hf_space_tag,
|
| 34 |
model_description=model_description,
|
| 35 |
organization=organization or "",
|
| 36 |
-
model_size=
|
| 37 |
pretrained = pretrained,
|
| 38 |
pretraining_data = pretraining_data or "",
|
| 39 |
publication_title=publication_title or "",
|
|
|
|
| 1 |
import asyncio
|
| 2 |
import gradio as gr
|
| 3 |
from backend.api import submit_model
|
| 4 |
+
from frontend.leaderboard import parse_parameter_count
|
| 5 |
|
| 6 |
|
| 7 |
def handle_submission(
|
|
|
|
| 23 |
# Basic validation
|
| 24 |
if not model_name or not hf_space_tag or not model_description or not organization or not model_size or not pretrained or not publication_title or not publication_link or not zero_shot or not few_shot:
|
| 25 |
return "<div style='color: red;'>Please fill in all required fields (*)</div>"
|
| 26 |
+
|
| 27 |
if "/" not in hf_space_tag:
|
| 28 |
return "<div style='color: red;'>HuggingFace space tag should be in format 'username/space-name'</div>"
|
| 29 |
+
|
| 30 |
+
# Parse and validate model_size
|
| 31 |
+
parsed_model_size = parse_parameter_count(model_size)
|
| 32 |
+
if model_size and parsed_model_size is None:
|
| 33 |
+
return "<div style='color: red;'>Invalid model size format. Use raw numbers (e.g., 120000000) or human-readable format (e.g., 120M, 0.12B)</div>"
|
| 34 |
+
|
| 35 |
# Process submission
|
| 36 |
try:
|
| 37 |
result = asyncio.run(submit_model(
|
|
|
|
| 39 |
hf_space_tag=hf_space_tag,
|
| 40 |
model_description=model_description,
|
| 41 |
organization=organization or "",
|
| 42 |
+
model_size=parsed_model_size,
|
| 43 |
pretrained = pretrained,
|
| 44 |
pretraining_data = pretraining_data or "",
|
| 45 |
publication_title=publication_title or "",
|