Spaces:
Sleeping
Sleeping
Peiran
commited on
Commit
·
1688aaf
1
Parent(s):
64125ec
Annotator ID from HF user: remove manual input, extract from gr.Request (X-Forwarded-User/username); wire through handlers; keep per-user dedup + global balancing
Browse files- __pycache__/app.cpython-311.pyc +0 -0
- app.py +29 -6
__pycache__/app.cpython-311.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
|
|
|
app.py
CHANGED
|
@@ -337,7 +337,29 @@ def _upload_eval_record_to_dataset(task_name: str, row: Dict[str, object]) -> Tu
|
|
| 337 |
return False, f"Exception: {type(e).__name__}: {e}"
|
| 338 |
|
| 339 |
|
| 340 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
pairs = load_task(task_name, annotator_id)
|
| 342 |
# Defaults for A and B (8 sliders total)
|
| 343 |
default_scores = [3, 3, 3, 3, 3, 3, 3, 3]
|
|
@@ -402,7 +424,6 @@ def on_pair_navigate(index: int, pairs: List[Dict[str, str]]):
|
|
| 402 |
|
| 403 |
def on_submit(
|
| 404 |
task_name: str,
|
| 405 |
-
annotator_id: str,
|
| 406 |
index: int,
|
| 407 |
pairs: List[Dict[str, str]],
|
| 408 |
a_physical_score: int,
|
|
@@ -413,6 +434,7 @@ def on_submit(
|
|
| 413 |
b_optical_score: int,
|
| 414 |
b_semantic_score: int,
|
| 415 |
b_overall_score: int,
|
|
|
|
| 416 |
):
|
| 417 |
if not task_name:
|
| 418 |
return (
|
|
@@ -440,6 +462,9 @@ def on_submit(
|
|
| 440 |
gr.update(value="No pending pairs to submit."),
|
| 441 |
)
|
| 442 |
|
|
|
|
|
|
|
|
|
|
| 443 |
pair = pairs[index]
|
| 444 |
score_map = {
|
| 445 |
# Model A
|
|
@@ -540,7 +565,6 @@ with gr.Blocks(title="VisArena Human Evaluation") as demo:
|
|
| 540 |
interactive=True,
|
| 541 |
value="Scene Composition & Object Insertion",
|
| 542 |
)
|
| 543 |
-
annotator_id_input = gr.Textbox(label="Annotator ID", placeholder="请输入你的唯一标识 (如昵称/学号)")
|
| 544 |
index_slider = gr.Slider(
|
| 545 |
label="Pair Index",
|
| 546 |
value=0,
|
|
@@ -580,7 +604,7 @@ with gr.Blocks(title="VisArena Human Evaluation") as demo:
|
|
| 580 |
# Event bindings
|
| 581 |
task_selector.change(
|
| 582 |
fn=on_task_change,
|
| 583 |
-
inputs=[task_selector,
|
| 584 |
outputs=[
|
| 585 |
pair_state,
|
| 586 |
index_slider,
|
|
@@ -624,7 +648,6 @@ with gr.Blocks(title="VisArena Human Evaluation") as demo:
|
|
| 624 |
fn=on_submit,
|
| 625 |
inputs=[
|
| 626 |
task_selector,
|
| 627 |
-
annotator_id_input,
|
| 628 |
index_slider,
|
| 629 |
pair_state,
|
| 630 |
a_physical_input,
|
|
@@ -658,7 +681,7 @@ with gr.Blocks(title="VisArena Human Evaluation") as demo:
|
|
| 658 |
# Auto-load default task on startup
|
| 659 |
demo.load(
|
| 660 |
fn=on_task_change,
|
| 661 |
-
inputs=[task_selector,
|
| 662 |
outputs=[
|
| 663 |
pair_state,
|
| 664 |
index_slider,
|
|
|
|
| 337 |
return False, f"Exception: {type(e).__name__}: {e}"
|
| 338 |
|
| 339 |
|
| 340 |
+
def _extract_annotator_id(request: Optional[gr.Request]) -> str:
|
| 341 |
+
"""Best-effort extraction of a stable user identifier on HF Spaces.
|
| 342 |
+
Priority: request.username -> X-Forwarded-User header -> cookies/user-id -> env/session fallback.
|
| 343 |
+
"""
|
| 344 |
+
try:
|
| 345 |
+
if request is None:
|
| 346 |
+
return ""
|
| 347 |
+
# gradio>=4.0 may set username for Spaces-authenticated users
|
| 348 |
+
username = getattr(request, "username", None)
|
| 349 |
+
if username:
|
| 350 |
+
return str(username)
|
| 351 |
+
headers = getattr(request, "headers", {}) or {}
|
| 352 |
+
for k in ("x-forwarded-user", "x-user", "x-hub-user"):
|
| 353 |
+
v = headers.get(k) or headers.get(k.upper())
|
| 354 |
+
if v:
|
| 355 |
+
return str(v)
|
| 356 |
+
except Exception:
|
| 357 |
+
pass
|
| 358 |
+
return ""
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
def on_task_change(task_name: str, _state_pairs: List[Dict[str, str]], request: gr.Request):
|
| 362 |
+
annotator_id = _extract_annotator_id(request)
|
| 363 |
pairs = load_task(task_name, annotator_id)
|
| 364 |
# Defaults for A and B (8 sliders total)
|
| 365 |
default_scores = [3, 3, 3, 3, 3, 3, 3, 3]
|
|
|
|
| 424 |
|
| 425 |
def on_submit(
|
| 426 |
task_name: str,
|
|
|
|
| 427 |
index: int,
|
| 428 |
pairs: List[Dict[str, str]],
|
| 429 |
a_physical_score: int,
|
|
|
|
| 434 |
b_optical_score: int,
|
| 435 |
b_semantic_score: int,
|
| 436 |
b_overall_score: int,
|
| 437 |
+
request: gr.Request,
|
| 438 |
):
|
| 439 |
if not task_name:
|
| 440 |
return (
|
|
|
|
| 462 |
gr.update(value="No pending pairs to submit."),
|
| 463 |
)
|
| 464 |
|
| 465 |
+
# Resolve annotator id from request
|
| 466 |
+
annotator_id = _extract_annotator_id(request)
|
| 467 |
+
|
| 468 |
pair = pairs[index]
|
| 469 |
score_map = {
|
| 470 |
# Model A
|
|
|
|
| 565 |
interactive=True,
|
| 566 |
value="Scene Composition & Object Insertion",
|
| 567 |
)
|
|
|
|
| 568 |
index_slider = gr.Slider(
|
| 569 |
label="Pair Index",
|
| 570 |
value=0,
|
|
|
|
| 604 |
# Event bindings
|
| 605 |
task_selector.change(
|
| 606 |
fn=on_task_change,
|
| 607 |
+
inputs=[task_selector, pair_state],
|
| 608 |
outputs=[
|
| 609 |
pair_state,
|
| 610 |
index_slider,
|
|
|
|
| 648 |
fn=on_submit,
|
| 649 |
inputs=[
|
| 650 |
task_selector,
|
|
|
|
| 651 |
index_slider,
|
| 652 |
pair_state,
|
| 653 |
a_physical_input,
|
|
|
|
| 681 |
# Auto-load default task on startup
|
| 682 |
demo.load(
|
| 683 |
fn=on_task_change,
|
| 684 |
+
inputs=[task_selector, pair_state],
|
| 685 |
outputs=[
|
| 686 |
pair_state,
|
| 687 |
index_slider,
|