Spaces:
Sleeping
Sleeping
SAGE OSS Evaluator
commited on
Commit
·
a84c2ea
1
Parent(s):
1738ea8
update
Browse files
app.py
CHANGED
|
@@ -302,8 +302,23 @@ with demo:
|
|
| 302 |
|
| 303 |
# 提交按钮 (登录功能暂时注释)
|
| 304 |
with gr.Row():
|
| 305 |
-
|
| 306 |
submit_button = gr.Button("Submit Results", variant="primary", size="lg")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
|
| 308 |
# 进度显示和结果显示区域
|
| 309 |
progress_info = gr.HTML() # 进度显示区域
|
|
@@ -331,12 +346,17 @@ with demo:
|
|
| 331 |
"""
|
| 332 |
return progress_html
|
| 333 |
|
| 334 |
-
def handle_submission(file_upload, org_name, email, progress=gr.Progress()):
|
| 335 |
try:
|
| 336 |
# 步骤1: 基本验证
|
| 337 |
progress(0.1, desc="验证提交信息...")
|
| 338 |
yield show_progress(1, "验证提交信息"), ""
|
| 339 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 340 |
if not file_upload:
|
| 341 |
yield "", format_error("请选择要上传的文件")
|
| 342 |
return
|
|
@@ -360,6 +380,12 @@ with demo:
|
|
| 360 |
import time
|
| 361 |
time.sleep(0.5) # 让用户看到进度更新
|
| 362 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
# 步骤3: 上传到OSS
|
| 364 |
progress(0.6, desc="上传文件到OSS...")
|
| 365 |
yield show_progress(3, "上传文件到OSS存储"), ""
|
|
@@ -374,6 +400,12 @@ with demo:
|
|
| 374 |
|
| 375 |
time.sleep(0.5) # 让用户看到完成状态
|
| 376 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
# 生成成功信息
|
| 378 |
success_info = f"""
|
| 379 |
<div style="background-color: #d4edda; border: 1px solid #c3e6cb; border-radius: 5px; padding: 15px; margin: 10px 0;">
|
|
@@ -397,7 +429,7 @@ with demo:
|
|
| 397 |
|
| 398 |
submit_button.click(
|
| 399 |
handle_submission,
|
| 400 |
-
inputs=[file_upload, org_textbox, email_textbox],
|
| 401 |
outputs=[progress_info, submission_result],
|
| 402 |
show_progress=True
|
| 403 |
)
|
|
|
|
| 302 |
|
| 303 |
# 提交按钮 (登录功能暂时注释)
|
| 304 |
with gr.Row():
|
| 305 |
+
login_button = gr.LoginButton("🔐 Login with HuggingFace", size="lg")
|
| 306 |
submit_button = gr.Button("Submit Results", variant="primary", size="lg")
|
| 307 |
+
# 登录状态与用户信息
|
| 308 |
+
profile_state = gr.State()
|
| 309 |
+
login_status = gr.Markdown(visible=True)
|
| 310 |
+
|
| 311 |
+
def on_login(profile: gr.OAuthProfile):
|
| 312 |
+
try:
|
| 313 |
+
if profile and getattr(profile, "username", None):
|
| 314 |
+
name = profile.username
|
| 315 |
+
text = f"✅ 已登录: **{name}**"
|
| 316 |
+
else:
|
| 317 |
+
text = "❌ 登录失败,请重试"
|
| 318 |
+
return profile, text
|
| 319 |
+
except Exception:
|
| 320 |
+
return None, "❌ 登录失败,请重试"
|
| 321 |
+
login_button.click(on_login, inputs=[], outputs=[profile_state, login_status])
|
| 322 |
|
| 323 |
# 进度显示和结果显示区域
|
| 324 |
progress_info = gr.HTML() # 进度显示区域
|
|
|
|
| 346 |
"""
|
| 347 |
return progress_html
|
| 348 |
|
| 349 |
+
def handle_submission(file_upload, org_name, email, user_profile, progress=gr.Progress()):
|
| 350 |
try:
|
| 351 |
# 步骤1: 基本验证
|
| 352 |
progress(0.1, desc="验证提交信息...")
|
| 353 |
yield show_progress(1, "验证提交信息"), ""
|
| 354 |
|
| 355 |
+
# 校验登录
|
| 356 |
+
if user_profile is None or getattr(user_profile, "username", None) is None:
|
| 357 |
+
yield "", format_error("请先登录 HuggingFace 账号后再提交")
|
| 358 |
+
return
|
| 359 |
+
|
| 360 |
if not file_upload:
|
| 361 |
yield "", format_error("请选择要上传的文件")
|
| 362 |
return
|
|
|
|
| 380 |
import time
|
| 381 |
time.sleep(0.5) # 让用户看到进度更新
|
| 382 |
|
| 383 |
+
# 用户资格检查(账号年龄/频率/重复提交)
|
| 384 |
+
eligible, msg = check_user_submission_eligibility(user_profile, org_name)
|
| 385 |
+
if not eligible:
|
| 386 |
+
yield "", format_error(msg)
|
| 387 |
+
return
|
| 388 |
+
|
| 389 |
# 步骤3: 上传到OSS
|
| 390 |
progress(0.6, desc="上传文件到OSS...")
|
| 391 |
yield show_progress(3, "上传文件到OSS存储"), ""
|
|
|
|
| 400 |
|
| 401 |
time.sleep(0.5) # 让用户看到完成状态
|
| 402 |
|
| 403 |
+
# 记录提交历史
|
| 404 |
+
try:
|
| 405 |
+
record_user_submission(user_profile, org_name, email)
|
| 406 |
+
except Exception:
|
| 407 |
+
pass
|
| 408 |
+
|
| 409 |
# 生成成功信息
|
| 410 |
success_info = f"""
|
| 411 |
<div style="background-color: #d4edda; border: 1px solid #c3e6cb; border-radius: 5px; padding: 15px; margin: 10px 0;">
|
|
|
|
| 429 |
|
| 430 |
submit_button.click(
|
| 431 |
handle_submission,
|
| 432 |
+
inputs=[file_upload, org_textbox, email_textbox, profile_state],
|
| 433 |
outputs=[progress_info, submission_result],
|
| 434 |
show_progress=True
|
| 435 |
)
|