Spaces:
Running
Running
Commit ·
2c95aa5
1
Parent(s): d763eab
Compactify UI and increase image sizes.
Browse files
app.py
CHANGED
|
@@ -243,30 +243,23 @@ def _select_groups(cfg: dict, rating_pref: str) -> list[str]:
|
|
| 243 |
if g.endswith(f"_{rating_pref}")
|
| 244 |
]
|
| 245 |
|
| 246 |
-
def
|
| 247 |
-
|
| 248 |
-
url = f"https://e621.net/posts/{post_id}"
|
| 249 |
-
row = f"{url} | Times rated: {total_votes}"
|
| 250 |
-
return f"{label}: {row}" if label else row
|
| 251 |
|
| 252 |
def _render_current(state: dict, submit_status: str = "") -> tuple:
|
| 253 |
_reload_stats_if_due()
|
| 254 |
-
wins_a, losses_a = _pool_df.iloc[_md5_to_idx[state["key_a"]], [WINS_LOC, LOSSES_LOC]]
|
| 255 |
-
wins_b, losses_b = _pool_df.iloc[_md5_to_idx[state["key_b"]], [WINS_LOC, LOSSES_LOC]]
|
| 256 |
-
title_a = "Image A"
|
| 257 |
-
title_b = "Image B"
|
| 258 |
-
img_a_html = f"<div class=\"rating-card\"><div class=\"rating-card-title\"><strong>{html.escape(title_a)}</strong></div><div class=\"rating-image-frame\"><img src=\"{html.escape(state['url_a'])}\" class=\"rating-image\" loading=\"eager\" referrerpolicy=\"no-referrer\"></div></div>"
|
| 259 |
-
img_b_html = f"<div class=\"rating-card\"><div class=\"rating-card-title\"><strong>{html.escape(title_b)}</strong></div><div class=\"rating-image-frame\"><img src=\"{html.escape(state['url_b'])}\" class=\"rating-image\" loading=\"eager\" referrerpolicy=\"no-referrer\"></div></div>"
|
| 260 |
-
link_a = _format_rating_post_row(state["id_a"], wins_a, losses_a, label="Image A")
|
| 261 |
-
link_b = _format_rating_post_row(state["id_b"], wins_b, losses_b, label="Image B")
|
| 262 |
-
can_go_back = bool(state.get("can_go_back"))
|
| 263 |
-
back_md = "[Undo Rating (Ctrl+z)](#back)" if can_go_back else "<span class='subtle-back-link-disabled'>Undo Rating (Ctrl+z)</span>"
|
| 264 |
-
group_md = f"<span class='subtle-note'>Group: {state['group']}</span>"
|
| 265 |
-
pair_reason = state.get("pair_reason", "")
|
| 266 |
-
pair_reason_md = f"<span class='subtle-note'>Pair: {html.escape(pair_reason)}</span>" if pair_reason else ""
|
| 267 |
-
status_md = f"<span class='submit-status-msg'>{html.escape(submit_status)}</span>" if submit_status else ""
|
| 268 |
-
return img_a_html, img_b_html, link_a, link_b, back_md, group_md, pair_reason_md, status_md, state
|
| 269 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
|
| 271 |
def _normalize_rating_pref(pref: str | None) -> str:
|
| 272 |
return pref if pref in ("safe", "all") else "safe"
|
|
@@ -443,7 +436,7 @@ def go_back(state: dict) -> tuple:
|
|
| 443 |
# -- UI ---------------------------------------------------------------------
|
| 444 |
|
| 445 |
with gr.Blocks(
|
| 446 |
-
title="
|
| 447 |
head="""
|
| 448 |
<script>
|
| 449 |
const VOTE_COOLDOWN_MS = 1500;
|
|
@@ -588,7 +581,7 @@ with gr.Blocks(
|
|
| 588 |
}
|
| 589 |
.rating-image-frame {
|
| 590 |
width: 100%;
|
| 591 |
-
height:
|
| 592 |
border: 1px solid #e6e6e6;
|
| 593 |
border-radius: 8px;
|
| 594 |
background: #333;
|
|
@@ -650,6 +643,9 @@ with gr.Blocks(
|
|
| 650 |
object-fit: contain !important;
|
| 651 |
background: #1f2937;
|
| 652 |
}
|
|
|
|
|
|
|
|
|
|
| 653 |
""",
|
| 654 |
) as demo:
|
| 655 |
state = gr.State({})
|
|
@@ -666,13 +662,16 @@ with gr.Blocks(
|
|
| 666 |
img_a = gr.HTML(elem_id="img-a")
|
| 667 |
img_b = gr.HTML(elem_id="img-b")
|
| 668 |
|
| 669 |
-
with gr.Row():
|
| 670 |
btn_a = gr.Button("👍 Prefer A", variant="primary", elem_id="btn-vote-a")
|
| 671 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 672 |
btn_b = gr.Button("👍 Prefer B", variant="primary", elem_id="btn-vote-b")
|
| 673 |
|
| 674 |
with gr.Accordion("Settings", open=False):
|
| 675 |
-
gr.Markdown("<span style='color:#888;font-size:0.9em;'>Advanced options</span>")
|
| 676 |
rating_dd = gr.Dropdown(
|
| 677 |
choices=["safe", "all"],
|
| 678 |
value="safe",
|
|
@@ -682,19 +681,13 @@ with gr.Blocks(
|
|
| 682 |
submit_key_tb = gr.Textbox(
|
| 683 |
value="",
|
| 684 |
type="password",
|
| 685 |
-
label="Submit
|
| 686 |
elem_id="submit-key",
|
| 687 |
)
|
| 688 |
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
btn_back_action = gr.Button("Undo Rating (Ctrl+z)", elem_id="btn-back-action", elem_classes=["hidden-action-btn"])
|
| 693 |
-
details_md = gr.Markdown()
|
| 694 |
-
pair_reason_md = gr.Markdown()
|
| 695 |
-
submit_status_md = gr.Markdown(elem_id="submit-status")
|
| 696 |
-
gr.Markdown("<span class='subtle-note'>Dataset: <a href='https://huggingface.co/datasets/taigasan/e6-visual-ratings' target='_blank' rel='noopener noreferrer'>taigasan/e6-visual-ratings</a></span>")
|
| 697 |
-
gr.Markdown("<span class='subtle-note'>Keyboard Shortcuts: ⬅️ vote A, ⬆️ same quality, ➡️ vote B, Ctrl+z undo rating</span>")
|
| 698 |
|
| 699 |
(
|
| 700 |
results_summary_md,
|
|
@@ -709,7 +702,7 @@ with gr.Blocks(
|
|
| 709 |
results_page_offset_state,
|
| 710 |
) = add_results_tab(_pool_df)
|
| 711 |
|
| 712 |
-
outputs = [img_a, img_b,
|
| 713 |
results_outputs = [
|
| 714 |
results_summary_md,
|
| 715 |
results_score_distribution_plot,
|
|
|
|
| 243 |
if g.endswith(f"_{rating_pref}")
|
| 244 |
]
|
| 245 |
|
| 246 |
+
def _format_rating_post_title(post_id: int, votes: int, label: str) -> str:
|
| 247 |
+
return f"<strong>{label}</strong>: <a href=\"https://e621.net/posts/{post_id}\" target=\"_blank\" rel=\"noreferrer\">Post #{post_id}</a> | {votes} {'Vote' if votes == 1 else 'Votes'}"
|
|
|
|
|
|
|
|
|
|
| 248 |
|
| 249 |
def _render_current(state: dict, submit_status: str = "") -> tuple:
|
| 250 |
_reload_stats_if_due()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
|
| 252 |
+
votes_a = _pool_df.iloc[_md5_to_idx[state["key_a"]], VOTES_LOC]
|
| 253 |
+
votes_b = _pool_df.iloc[_md5_to_idx[state["key_b"]], VOTES_LOC]
|
| 254 |
+
title_a = _format_rating_post_title(state["id_a"], votes_a, "Image A")
|
| 255 |
+
title_b = _format_rating_post_title(state["id_b"], votes_b, "Image B")
|
| 256 |
+
img_a_html = f"<div class=\"rating-card\"><div class=\"rating-card-title\">{title_a}</div><div class=\"rating-image-frame\"><img src=\"{html.escape(state['url_a'])}\" class=\"rating-image\" loading=\"eager\" referrerpolicy=\"no-referrer\"></div></div>"
|
| 257 |
+
img_b_html = f"<div class=\"rating-card\"><div class=\"rating-card-title\">{title_b}</div><div class=\"rating-image-frame\"><img src=\"{html.escape(state['url_b'])}\" class=\"rating-image\" loading=\"eager\" referrerpolicy=\"no-referrer\"></div></div>"
|
| 258 |
+
|
| 259 |
+
can_go_back = bool(state.get("pending", ()))
|
| 260 |
+
pair_details = f"/ {state['group']} / {state.get('pair_reason', 'unknown')}"
|
| 261 |
+
|
| 262 |
+
return img_a_html, img_b_html, gr.Button(interactive=can_go_back), html.escape(pair_details), html.escape(submit_status), state
|
| 263 |
|
| 264 |
def _normalize_rating_pref(pref: str | None) -> str:
|
| 265 |
return pref if pref in ("safe", "all") else "safe"
|
|
|
|
| 436 |
# -- UI ---------------------------------------------------------------------
|
| 437 |
|
| 438 |
with gr.Blocks(
|
| 439 |
+
title="e621 Visual Ratings",
|
| 440 |
head="""
|
| 441 |
<script>
|
| 442 |
const VOTE_COOLDOWN_MS = 1500;
|
|
|
|
| 581 |
}
|
| 582 |
.rating-image-frame {
|
| 583 |
width: 100%;
|
| 584 |
+
height: 720px;
|
| 585 |
border: 1px solid #e6e6e6;
|
| 586 |
border-radius: 8px;
|
| 587 |
background: #333;
|
|
|
|
| 643 |
object-fit: contain !important;
|
| 644 |
background: #1f2937;
|
| 645 |
}
|
| 646 |
+
a {
|
| 647 |
+
padding: 0 !important;
|
| 648 |
+
}
|
| 649 |
""",
|
| 650 |
) as demo:
|
| 651 |
state = gr.State({})
|
|
|
|
| 662 |
img_a = gr.HTML(elem_id="img-a")
|
| 663 |
img_b = gr.HTML(elem_id="img-b")
|
| 664 |
|
| 665 |
+
with gr.Row(equal_height=True):
|
| 666 |
btn_a = gr.Button("👍 Prefer A", variant="primary", elem_id="btn-vote-a")
|
| 667 |
+
|
| 668 |
+
with gr.Column(scale=0), gr.Group():
|
| 669 |
+
btn_skip = gr.Button("🤏 Same Quality", elem_id="btn-skip")
|
| 670 |
+
btn_back_action = gr.Button("↶ Undo", elem_id="btn-back-action")
|
| 671 |
+
|
| 672 |
btn_b = gr.Button("👍 Prefer B", variant="primary", elem_id="btn-vote-b")
|
| 673 |
|
| 674 |
with gr.Accordion("Settings", open=False):
|
|
|
|
| 675 |
rating_dd = gr.Dropdown(
|
| 676 |
choices=["safe", "all"],
|
| 677 |
value="safe",
|
|
|
|
| 681 |
submit_key_tb = gr.Textbox(
|
| 682 |
value="",
|
| 683 |
type="password",
|
| 684 |
+
label="Submit Key",
|
| 685 |
elem_id="submit-key",
|
| 686 |
)
|
| 687 |
|
| 688 |
+
pair_details = gr.HTML(html_template="Dataset: <a href='https://huggingface.co/datasets/taigasan/e6-visual-ratings' target='_blank' rel='noopener noreferrer'>taigasan/e6-visual-ratings</a> ${value}")
|
| 689 |
+
submit_status = gr.HTML(html_template="<span class='submit-status-msg'>${value}</span>")
|
| 690 |
+
gr.HTML("<span class='subtle-note'>Keyboard Shortcuts: ⬅️ Vote A, ⬆️ Same Quality, ➡️ Vote B, Ctrl+Z Undo</span>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 691 |
|
| 692 |
(
|
| 693 |
results_summary_md,
|
|
|
|
| 702 |
results_page_offset_state,
|
| 703 |
) = add_results_tab(_pool_df)
|
| 704 |
|
| 705 |
+
outputs = [img_a, img_b, btn_back_action, pair_details, submit_status, state]
|
| 706 |
results_outputs = [
|
| 707 |
results_summary_md,
|
| 708 |
results_score_distribution_plot,
|