yangzhitao commited on
Commit
6ad8c8e
·
1 Parent(s): 480ac67

feat: enhance submission process by adding user ID handling and improving JSON structure for submissions

Browse files
app.py CHANGED
@@ -574,14 +574,24 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
574
  revision: str,
575
  precision: str,
576
  weight_type: str,
577
- model_type: str, # Currently not used but kept for future use
578
  json_str: str,
579
  commit_message: str,
580
  *benchmark_values,
 
581
  ):
582
  """Submit with either form data or JSON"""
583
  import json
584
 
 
 
 
 
 
 
 
 
 
585
  # If JSON is provided, use it; otherwise build from form
586
  if json_str and json_str.strip():
587
  try:
@@ -610,8 +620,18 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
610
  except Exception as e:
611
  return styled_error(f"Error building JSON: {str(e)}")
612
 
613
- # Call the submit function
614
- return add_new_submit(model, base_model, revision, precision, weight_type, final_json, commit_message)
 
 
 
 
 
 
 
 
 
 
615
 
616
  # Create submit button outside form_container so it can be referenced
617
  # Initially hidden and disabled (will be shown and enabled when user logs in)
 
574
  revision: str,
575
  precision: str,
576
  weight_type: str,
577
+ model_type: str,
578
  json_str: str,
579
  commit_message: str,
580
  *benchmark_values,
581
+ oauth_profile: gr.OAuthProfile | None = None,
582
  ):
583
  """Submit with either form data or JSON"""
584
  import json
585
 
586
+ # Check if user is logged in
587
+ if oauth_profile is None:
588
+ return styled_error("Please log in before submitting.")
589
+
590
+ # Extract user_id from OAuth profile
591
+ user_id = oauth_profile.get("preferred_username") or oauth_profile.get("sub", None)
592
+ if not user_id:
593
+ return styled_error("Unable to get user ID. Please try logging in again.")
594
+
595
  # If JSON is provided, use it; otherwise build from form
596
  if json_str and json_str.strip():
597
  try:
 
620
  except Exception as e:
621
  return styled_error(f"Error building JSON: {str(e)}")
622
 
623
+ # Call the submit function with all fields including user_id
624
+ return add_new_submit(
625
+ model=model,
626
+ base_model=base_model,
627
+ revision=revision,
628
+ precision=precision,
629
+ weight_type=weight_type,
630
+ model_type=model_type,
631
+ json_str=final_json,
632
+ commit_message=commit_message,
633
+ user_id=user_id,
634
+ )
635
 
636
  # Create submit button outside form_container so it can be referenced
637
  # Initially hidden and disabled (will be shown and enabled when user logs in)
src/backend/routes/hf.py CHANGED
@@ -66,19 +66,6 @@ async def upload_file_content_handler(
66
  commit_message: str | None = None,
67
  ):
68
  """Community submit handler."""
69
-
70
- # FIXME: debug
71
- import rich
72
-
73
- rich.print({
74
- "path_or_fileobj": path_or_fileobj,
75
- "path_in_repo": path_in_repo,
76
- "repo_id": repo_id,
77
- "repo_type": repo_type,
78
- "commit_message": commit_message,
79
- })
80
- raise RuntimeError("debug")
81
-
82
  commit_info = settings.hf_api.upload_file(
83
  path_or_fileobj=path_or_fileobj,
84
  path_in_repo=path_in_repo,
 
66
  commit_message: str | None = None,
67
  ):
68
  """Community submit handler."""
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  commit_info = settings.hf_api.upload_file(
70
  path_or_fileobj=path_or_fileobj,
71
  path_in_repo=path_in_repo,
src/backend/schemas.py CHANGED
@@ -100,8 +100,11 @@ class HfRepoUrl(BaseModel):
100
  class CommunitySubmit_Params(BaseModel):
101
  username: Annotated[str, Field(description='The username of the user. e.g. "Qwen"')]
102
 
103
- # Commit info
104
  model_id: Annotated[str, Field(description='The model id. e.g. "Qwen/Qwen2.5-3B"')]
 
 
 
105
  model_sha: Annotated[
106
  str, Field(description='The model sha or "main". e.g. "3aab1f1954e9cc14eb9509a215f9e5ca08227a9b"')
107
  ] = "main"
@@ -132,8 +135,15 @@ class CommunitySubmit_Params(BaseModel):
132
  "float8_e8m0fnu",
133
  "float4_e2m1fn_x2",
134
  ]
135
- content: Annotated[str, Field(description='The content of the file in JSON format to upload.')]
136
  weight_type: Literal["Original"] | str = "Original"
 
 
 
 
 
 
 
 
137
 
138
  @computed_field
139
  @property
@@ -149,5 +159,3 @@ class CommunitySubmit_Params(BaseModel):
149
  "username_invalid", "Username {username!r} is invalid.", {"username": self.username}
150
  )
151
  return f"{model_name}_eval_request_False_{self.model_dtype}_{self.weight_type}_{self.username}.json"
152
-
153
- commit_message: str | None = None
 
100
  class CommunitySubmit_Params(BaseModel):
101
  username: Annotated[str, Field(description='The username of the user. e.g. "Qwen"')]
102
 
103
+ # Model info
104
  model_id: Annotated[str, Field(description='The model id. e.g. "Qwen/Qwen2.5-3B"')]
105
+ base_model: Annotated[
106
+ str, Field(description='The base model name (for delta or adapter weights). e.g. "Qwen/Qwen2.5-3B"')
107
+ ] = ""
108
  model_sha: Annotated[
109
  str, Field(description='The model sha or "main". e.g. "3aab1f1954e9cc14eb9509a215f9e5ca08227a9b"')
110
  ] = "main"
 
135
  "float8_e8m0fnu",
136
  "float4_e2m1fn_x2",
137
  ]
 
138
  weight_type: Literal["Original"] | str = "Original"
139
+ model_type: Annotated[str, Field(description='The model type. e.g. "pretrained", "fine-tuned"')] = ""
140
+
141
+ # Submission info
142
+ content: Annotated[str, Field(description='The content of the file in JSON format to upload.')]
143
+ submit_time: Annotated[
144
+ str, Field(description='The submission time in UTC ISO format. e.g. "2025-01-15T10:30:00Z"')
145
+ ]
146
+ commit_message: str | None = None
147
 
148
  @computed_field
149
  @property
 
159
  "username_invalid", "Username {username!r} is invalid.", {"username": self.username}
160
  )
161
  return f"{model_name}_eval_request_False_{self.model_dtype}_{self.weight_type}_{self.username}.json"
 
 
src/submission/submit.py CHANGED
@@ -23,21 +23,40 @@ REQUESTED_MODELS: set[str] | None = None
23
 
24
 
25
  def add_new_submit(
26
- model: str, base_model: str, revision: str, precision: str, weight_type: str, json_str: str, commit_message: str
 
 
 
 
 
 
 
 
27
  ):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  global REQUESTED_MODELS
29
  if not REQUESTED_MODELS:
30
  REQUESTED_MODELS, _ = already_submitted_models(settings.EVAL_REQUESTS_PATH.as_posix())
31
 
32
- user_name = ""
33
- model_path = model
34
- if "/" in model:
35
- user_name = model.split("/")[0]
36
- model_path = model.split("/")[1]
37
 
38
- precision = precision.split(" ")[0]
39
  # Does the model actually exist?
40
- if revision == "":
41
  revision = "main"
42
 
43
  # Is the model on the hub?
@@ -67,13 +86,52 @@ def add_new_submit(
67
  except Exception:
68
  return styled_error("Please select a license for your model")
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  request_json = {
71
  "username": user_name,
72
  "model_id": model,
 
73
  "model_sha": revision,
74
  "model_dtype": precision,
75
- "content": json_str,
76
  "weight_type": weight_type,
 
 
 
77
  "commit_message": commit_message,
78
  }
79
 
 
23
 
24
 
25
  def add_new_submit(
26
+ model: str,
27
+ base_model: str,
28
+ revision: str,
29
+ precision: str,
30
+ weight_type: str,
31
+ model_type: str,
32
+ json_str: str,
33
+ commit_message: str,
34
+ user_id: str,
35
  ):
36
+ """
37
+ Submit a new evaluation request.
38
+
39
+ Args:
40
+ model: Model name (e.g., "org/model_name")
41
+ base_model: Base model name (for delta or adapter weights)
42
+ revision: Model revision/commit (defaults to "main" if empty)
43
+ precision: Model precision (e.g., "float16", "bfloat16")
44
+ weight_type: Weight type (e.g., "Original", "Delta", "Adapter")
45
+ model_type: Model type (e.g., "pretrained", "fine-tuned")
46
+ json_str: JSON string containing config and results
47
+ commit_message: Optional commit message
48
+ user_id: Submitter's HuggingFace user ID/username (from OAuth)
49
+ """
50
  global REQUESTED_MODELS
51
  if not REQUESTED_MODELS:
52
  REQUESTED_MODELS, _ = already_submitted_models(settings.EVAL_REQUESTS_PATH.as_posix())
53
 
54
+ # Use provided user_id, or extract from model name as fallback
55
+ user_name = user_id
 
 
 
56
 
57
+ precision = precision.split(" ")[0] if precision else "float16"
58
  # Does the model actually exist?
59
+ if not revision or revision == "":
60
  revision = "main"
61
 
62
  # Is the model on the hub?
 
86
  except Exception:
87
  return styled_error("Please select a license for your model")
88
 
89
+ # Validate required fields
90
+ if not model or not model.strip():
91
+ return styled_error("Model name is required.")
92
+ if not user_name or not user_name.strip():
93
+ return styled_error("User ID/username is required. Please make sure you are logged in.")
94
+
95
+ # Get current UTC time for submit_time
96
+ current_time = datetime.now(UTC).strftime("%Y-%m-%dT%H:%M:%SZ")
97
+
98
+ # Parse the evaluation results JSON (json_str contains config and results)
99
+ try:
100
+ eval_results = json.loads(json_str)
101
+ except json.JSONDecodeError:
102
+ return styled_error("Invalid evaluation results JSON format.")
103
+
104
+ # Organize all fields into a comprehensive JSON structure for the content field
105
+ # This will be the complete JSON that gets uploaded as a file
106
+ complete_submission_content = {
107
+ "username": user_name,
108
+ "model_id": model,
109
+ "base_model": base_model or "",
110
+ "model_sha": revision,
111
+ "model_dtype": precision,
112
+ "weight_type": weight_type,
113
+ "model_type": model_type or "",
114
+ "submit_time": current_time,
115
+ "commit_message": commit_message,
116
+ # Include the evaluation results (config and results)
117
+ "config": eval_results.get("config", {}),
118
+ "results": eval_results.get("results", {}),
119
+ }
120
+
121
+ # Convert the complete submission content to JSON string for the content field
122
+ complete_content_json_str = json.dumps(complete_submission_content, indent=2, ensure_ascii=False)
123
+
124
+ # Request JSON for the API call - includes all fields separately
125
  request_json = {
126
  "username": user_name,
127
  "model_id": model,
128
+ "base_model": base_model or "",
129
  "model_sha": revision,
130
  "model_dtype": precision,
 
131
  "weight_type": weight_type,
132
+ "model_type": model_type or "",
133
+ "content": complete_content_json_str, # Complete JSON with all fields
134
+ "submit_time": current_time,
135
  "commit_message": commit_message,
136
  }
137