Force darker demo text styling
Browse files
app.py
CHANGED
|
@@ -39,11 +39,31 @@ APP_THEME = gr.themes.Soft(
|
|
| 39 |
)
|
| 40 |
APP_CSS = """
|
| 41 |
.gradio-container {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
color: #2f281d;
|
| 43 |
background:
|
| 44 |
radial-gradient(circle at top left, #f7d58d 0%, rgba(247, 213, 141, 0.22) 22%, transparent 45%),
|
| 45 |
linear-gradient(180deg, #f7f4ea 0%, #efe8d7 100%);
|
| 46 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
.app-shell {
|
| 48 |
max-width: 1280px;
|
| 49 |
margin: 0 auto;
|
|
@@ -68,6 +88,10 @@ APP_CSS = """
|
|
| 68 |
color: #6e4b10;
|
| 69 |
font-weight: 600;
|
| 70 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
.result-card {
|
| 72 |
padding: 18px 20px;
|
| 73 |
border: 1px solid rgba(99, 75, 39, 0.16);
|
|
@@ -79,10 +103,11 @@ APP_CSS = """
|
|
| 79 |
margin: 0 0 8px;
|
| 80 |
font-size: 1.2rem;
|
| 81 |
letter-spacing: -0.02em;
|
|
|
|
| 82 |
}
|
| 83 |
.result-card p {
|
| 84 |
margin: 0 0 10px;
|
| 85 |
-
color: #
|
| 86 |
}
|
| 87 |
.result-section {
|
| 88 |
margin-top: 14px;
|
|
@@ -91,7 +116,8 @@ APP_CSS = """
|
|
| 91 |
font-size: 0.9rem;
|
| 92 |
text-transform: uppercase;
|
| 93 |
letter-spacing: 0.08em;
|
| 94 |
-
color: #
|
|
|
|
| 95 |
margin-bottom: 8px;
|
| 96 |
}
|
| 97 |
.result-list {
|
|
@@ -101,6 +127,10 @@ APP_CSS = """
|
|
| 101 |
}
|
| 102 |
.result-list li {
|
| 103 |
margin: 4px 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
}
|
| 105 |
.result-chip-row {
|
| 106 |
display: flex;
|
|
@@ -114,7 +144,8 @@ APP_CSS = """
|
|
| 114 |
border-radius: 999px;
|
| 115 |
background: #efe1bf;
|
| 116 |
border: 1px solid rgba(114, 87, 38, 0.14);
|
| 117 |
-
color: #
|
|
|
|
| 118 |
font-size: 0.92rem;
|
| 119 |
}
|
| 120 |
.reference-grid {
|
|
@@ -143,13 +174,19 @@ APP_CSS = """
|
|
| 143 |
font-size: 0.76rem;
|
| 144 |
letter-spacing: 0.08em;
|
| 145 |
text-transform: uppercase;
|
| 146 |
-
color: #
|
|
|
|
| 147 |
margin-bottom: 6px;
|
| 148 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
.reference-card-title {
|
| 150 |
font-size: 0.98rem;
|
| 151 |
line-height: 1.3;
|
| 152 |
-
color: #
|
| 153 |
font-weight: 600;
|
| 154 |
}
|
| 155 |
.upload-panel {
|
|
@@ -170,6 +207,13 @@ APP_CSS = """
|
|
| 170 |
.results-toggle label {
|
| 171 |
color: #2f281d;
|
| 172 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
"""
|
| 174 |
APP_ALLOWED_PATHS = [str(ASSETS_DIR)]
|
| 175 |
|
|
@@ -479,33 +523,33 @@ def format_prediction_report(
|
|
| 479 |
start=1,
|
| 480 |
):
|
| 481 |
top_prediction_items.append(
|
| 482 |
-
"<li>"
|
| 483 |
f"{html.escape(class_names[class_idx])} "
|
| 484 |
-
f"<span>({prob * 100:.2f}%)</span>"
|
| 485 |
"</li>"
|
| 486 |
)
|
| 487 |
|
| 488 |
reference_chips = []
|
| 489 |
for idx in reference_indices:
|
| 490 |
reference_chips.append(
|
| 491 |
-
f"<span class='result-chip'>{html.escape(class_names[idx])}</span>"
|
| 492 |
)
|
| 493 |
|
| 494 |
return f"""
|
| 495 |
-
<div class="result-card">
|
| 496 |
-
<h3>{html.escape(class_names[target_index])}</h3>
|
| 497 |
-
<p>
|
| 498 |
Predicted CUB class
|
| 499 |
-
<span class="result-chip">index {target_index}</span>
|
| 500 |
</p>
|
| 501 |
<div class="result-section">
|
| 502 |
-
<div class="result-section-title">Top Predictions</div>
|
| 503 |
<ol class="result-list">
|
| 504 |
{''.join(top_prediction_items)}
|
| 505 |
</ol>
|
| 506 |
</div>
|
| 507 |
<div class="result-section">
|
| 508 |
-
<div class="result-section-title">Reference Classes Used By Finer-CAM</div>
|
| 509 |
<div class="result-chip-row">
|
| 510 |
{''.join(reference_chips) if reference_chips else '<span class="result-chip">None</span>'}
|
| 511 |
</div>
|
|
@@ -553,7 +597,7 @@ def build_reference_cards_html(
|
|
| 553 |
<div class="reference-card">
|
| 554 |
<img src="{image_path_to_data_uri(image_path)}" alt="{html.escape(class_names[idx])}">
|
| 555 |
<div class="reference-card-body">
|
| 556 |
-
<div class="reference-card-index">Reference Class {idx}</div>
|
| 557 |
<div class="reference-card-title">{html.escape(class_names[idx])}</div>
|
| 558 |
</div>
|
| 559 |
</div>
|
|
@@ -562,16 +606,16 @@ def build_reference_cards_html(
|
|
| 562 |
|
| 563 |
if not cards:
|
| 564 |
return """
|
| 565 |
-
<div class="result-card">
|
| 566 |
-
<h3>Reference Class Images</h3>
|
| 567 |
-
<p>No reference classes were available for display.</p>
|
| 568 |
</div>
|
| 569 |
"""
|
| 570 |
|
| 571 |
return f"""
|
| 572 |
-
<div class="result-card">
|
| 573 |
-
<h3>Reference Class Images</h3>
|
| 574 |
-
<p>Representative CUB images retrieved for the reference classes used by Finer-CAM.</p>
|
| 575 |
<div class="reference-grid">
|
| 576 |
{''.join(cards)}
|
| 577 |
</div>
|
|
@@ -658,18 +702,18 @@ def run_visualization(
|
|
| 658 |
def build_demo():
|
| 659 |
with gr.Blocks() as demo:
|
| 660 |
with gr.Column(elem_classes=["app-shell"]):
|
| 661 |
-
gr.
|
| 662 |
"""
|
| 663 |
<div class="hero">
|
| 664 |
<h1>CUB Finer-CAM Playground</h1>
|
| 665 |
-
<p>
|
| 666 |
This demo is fixed to the CUB classifier trained on top of
|
| 667 |
-
<code>facebookresearch/dinov2</code> <code>dinov2_vitb14</code>.
|
| 668 |
Upload a bird image or pick a CUB example, then run Grad-CAM / Finer-CAM directly.
|
| 669 |
</p>
|
| 670 |
-
<p>
|
| 671 |
For more information on the
|
| 672 |
-
<a href="https://github.com/Imageomics/Finer-CAM" target="_blank" rel="noopener noreferrer">FinerCAM Project GitHub</a>.
|
| 673 |
</p>
|
| 674 |
</div>
|
| 675 |
"""
|
|
@@ -742,9 +786,9 @@ def build_demo():
|
|
| 742 |
finer_cam_output = gr.Image(label="Finer-CAM")
|
| 743 |
reference_gallery = gr.HTML(
|
| 744 |
"""
|
| 745 |
-
<div class="result-card">
|
| 746 |
-
<h3>Reference Class Images</h3>
|
| 747 |
-
<p>Run Finer-CAM to retrieve representative CUB images for the reference classes.</p>
|
| 748 |
</div>
|
| 749 |
"""
|
| 750 |
)
|
|
@@ -755,9 +799,9 @@ def build_demo():
|
|
| 755 |
):
|
| 756 |
prediction_report = gr.HTML(
|
| 757 |
"""
|
| 758 |
-
<div class="result-card">
|
| 759 |
-
<h3>Prediction Summary</h3>
|
| 760 |
-
<p>Run Finer-CAM to see the predicted class, top predictions, and reference classes.</p>
|
| 761 |
</div>
|
| 762 |
"""
|
| 763 |
)
|
|
|
|
| 39 |
)
|
| 40 |
APP_CSS = """
|
| 41 |
.gradio-container {
|
| 42 |
+
--body-text-color: #000000;
|
| 43 |
+
--body-text-color-subdued: #000000;
|
| 44 |
+
--block-label-text-color: #000000;
|
| 45 |
+
--block-title-text-color: #000000;
|
| 46 |
color: #2f281d;
|
| 47 |
background:
|
| 48 |
radial-gradient(circle at top left, #f7d58d 0%, rgba(247, 213, 141, 0.22) 22%, transparent 45%),
|
| 49 |
linear-gradient(180deg, #f7f4ea 0%, #efe8d7 100%);
|
| 50 |
}
|
| 51 |
+
.gradio-container .prose,
|
| 52 |
+
.gradio-container .prose p,
|
| 53 |
+
.gradio-container .prose span,
|
| 54 |
+
.gradio-container .prose strong,
|
| 55 |
+
.gradio-container .prose li,
|
| 56 |
+
.gradio-container label,
|
| 57 |
+
.gradio-container .block-title,
|
| 58 |
+
.gradio-container .block-label,
|
| 59 |
+
.gradio-container .gr-form,
|
| 60 |
+
.gradio-container .gr-form * {
|
| 61 |
+
color: #2f281d;
|
| 62 |
+
}
|
| 63 |
+
.gradio-container .prose a,
|
| 64 |
+
.gradio-container a {
|
| 65 |
+
color: #744d12;
|
| 66 |
+
}
|
| 67 |
.app-shell {
|
| 68 |
max-width: 1280px;
|
| 69 |
margin: 0 auto;
|
|
|
|
| 88 |
color: #6e4b10;
|
| 89 |
font-weight: 600;
|
| 90 |
}
|
| 91 |
+
.hero code {
|
| 92 |
+
color: #000000;
|
| 93 |
+
background: #eadfc7;
|
| 94 |
+
}
|
| 95 |
.result-card {
|
| 96 |
padding: 18px 20px;
|
| 97 |
border: 1px solid rgba(99, 75, 39, 0.16);
|
|
|
|
| 103 |
margin: 0 0 8px;
|
| 104 |
font-size: 1.2rem;
|
| 105 |
letter-spacing: -0.02em;
|
| 106 |
+
color: #241d14;
|
| 107 |
}
|
| 108 |
.result-card p {
|
| 109 |
margin: 0 0 10px;
|
| 110 |
+
color: #31291f;
|
| 111 |
}
|
| 112 |
.result-section {
|
| 113 |
margin-top: 14px;
|
|
|
|
| 116 |
font-size: 0.9rem;
|
| 117 |
text-transform: uppercase;
|
| 118 |
letter-spacing: 0.08em;
|
| 119 |
+
color: #000000 !important;
|
| 120 |
+
font-weight: 800 !important;
|
| 121 |
margin-bottom: 8px;
|
| 122 |
}
|
| 123 |
.result-list {
|
|
|
|
| 127 |
}
|
| 128 |
.result-list li {
|
| 129 |
margin: 4px 0;
|
| 130 |
+
color: #000000;
|
| 131 |
+
}
|
| 132 |
+
.result-list li span {
|
| 133 |
+
color: #000000;
|
| 134 |
}
|
| 135 |
.result-chip-row {
|
| 136 |
display: flex;
|
|
|
|
| 144 |
border-radius: 999px;
|
| 145 |
background: #efe1bf;
|
| 146 |
border: 1px solid rgba(114, 87, 38, 0.14);
|
| 147 |
+
color: #000000;
|
| 148 |
+
font-weight: 700;
|
| 149 |
font-size: 0.92rem;
|
| 150 |
}
|
| 151 |
.reference-grid {
|
|
|
|
| 174 |
font-size: 0.76rem;
|
| 175 |
letter-spacing: 0.08em;
|
| 176 |
text-transform: uppercase;
|
| 177 |
+
color: #000000 !important;
|
| 178 |
+
font-weight: 800 !important;
|
| 179 |
margin-bottom: 6px;
|
| 180 |
}
|
| 181 |
+
.result-card .result-section-title,
|
| 182 |
+
.reference-card .reference-card-index {
|
| 183 |
+
color: #000000 !important;
|
| 184 |
+
font-weight: 800 !important;
|
| 185 |
+
}
|
| 186 |
.reference-card-title {
|
| 187 |
font-size: 0.98rem;
|
| 188 |
line-height: 1.3;
|
| 189 |
+
color: #241d14;
|
| 190 |
font-weight: 600;
|
| 191 |
}
|
| 192 |
.upload-panel {
|
|
|
|
| 207 |
.results-toggle label {
|
| 208 |
color: #2f281d;
|
| 209 |
}
|
| 210 |
+
.upload-panel label,
|
| 211 |
+
.upload-panel .block-title,
|
| 212 |
+
.upload-panel .block-label,
|
| 213 |
+
.results-toggle .label-wrap,
|
| 214 |
+
.results-toggle .label-wrap span {
|
| 215 |
+
color: #241d14;
|
| 216 |
+
}
|
| 217 |
"""
|
| 218 |
APP_ALLOWED_PATHS = [str(ASSETS_DIR)]
|
| 219 |
|
|
|
|
| 523 |
start=1,
|
| 524 |
):
|
| 525 |
top_prediction_items.append(
|
| 526 |
+
"<li style='color:#000;'>"
|
| 527 |
f"{html.escape(class_names[class_idx])} "
|
| 528 |
+
f"<span style='color:#000;'>({prob * 100:.2f}%)</span>"
|
| 529 |
"</li>"
|
| 530 |
)
|
| 531 |
|
| 532 |
reference_chips = []
|
| 533 |
for idx in reference_indices:
|
| 534 |
reference_chips.append(
|
| 535 |
+
f"<span class='result-chip' style='color:#000;font-weight:700;'>{html.escape(class_names[idx])}</span>"
|
| 536 |
)
|
| 537 |
|
| 538 |
return f"""
|
| 539 |
+
<div class="result-card" style="color:#000;">
|
| 540 |
+
<h3 style="color:#000;font-weight:700;">{html.escape(class_names[target_index])}</h3>
|
| 541 |
+
<p style="color:#000;">
|
| 542 |
Predicted CUB class
|
| 543 |
+
<span class="result-chip" style="color:#000;font-weight:700;">index {target_index}</span>
|
| 544 |
</p>
|
| 545 |
<div class="result-section">
|
| 546 |
+
<div class="result-section-title" style="color:#000;font-weight:800;">Top Predictions</div>
|
| 547 |
<ol class="result-list">
|
| 548 |
{''.join(top_prediction_items)}
|
| 549 |
</ol>
|
| 550 |
</div>
|
| 551 |
<div class="result-section">
|
| 552 |
+
<div class="result-section-title" style="color:#000;font-weight:800;">Reference Classes Used By Finer-CAM</div>
|
| 553 |
<div class="result-chip-row">
|
| 554 |
{''.join(reference_chips) if reference_chips else '<span class="result-chip">None</span>'}
|
| 555 |
</div>
|
|
|
|
| 597 |
<div class="reference-card">
|
| 598 |
<img src="{image_path_to_data_uri(image_path)}" alt="{html.escape(class_names[idx])}">
|
| 599 |
<div class="reference-card-body">
|
| 600 |
+
<div class="reference-card-index" style="color:#000;font-weight:800;">Reference Class {idx}</div>
|
| 601 |
<div class="reference-card-title">{html.escape(class_names[idx])}</div>
|
| 602 |
</div>
|
| 603 |
</div>
|
|
|
|
| 606 |
|
| 607 |
if not cards:
|
| 608 |
return """
|
| 609 |
+
<div class="result-card" style="color:#000;">
|
| 610 |
+
<h3 style="color:#000;font-weight:700;">Reference Class Images</h3>
|
| 611 |
+
<p style="color:#000;">No reference classes were available for display.</p>
|
| 612 |
</div>
|
| 613 |
"""
|
| 614 |
|
| 615 |
return f"""
|
| 616 |
+
<div class="result-card" style="color:#000;">
|
| 617 |
+
<h3 style="color:#000;font-weight:700;">Reference Class Images</h3>
|
| 618 |
+
<p style="color:#000;">Representative CUB images retrieved for the reference classes used by Finer-CAM.</p>
|
| 619 |
<div class="reference-grid">
|
| 620 |
{''.join(cards)}
|
| 621 |
</div>
|
|
|
|
| 702 |
def build_demo():
|
| 703 |
with gr.Blocks() as demo:
|
| 704 |
with gr.Column(elem_classes=["app-shell"]):
|
| 705 |
+
gr.HTML(
|
| 706 |
"""
|
| 707 |
<div class="hero">
|
| 708 |
<h1>CUB Finer-CAM Playground</h1>
|
| 709 |
+
<p style="color:#000; opacity:1;">
|
| 710 |
This demo is fixed to the CUB classifier trained on top of
|
| 711 |
+
<code style="color:#000;">facebookresearch/dinov2</code> <code style="color:#000;">dinov2_vitb14</code>.
|
| 712 |
Upload a bird image or pick a CUB example, then run Grad-CAM / Finer-CAM directly.
|
| 713 |
</p>
|
| 714 |
+
<p style="color:#000; opacity:1;">
|
| 715 |
For more information on the
|
| 716 |
+
<a href="https://github.com/Imageomics/Finer-CAM" target="_blank" rel="noopener noreferrer" style="color:#000; font-weight:700; text-decoration:underline;">FinerCAM Project GitHub</a>.
|
| 717 |
</p>
|
| 718 |
</div>
|
| 719 |
"""
|
|
|
|
| 786 |
finer_cam_output = gr.Image(label="Finer-CAM")
|
| 787 |
reference_gallery = gr.HTML(
|
| 788 |
"""
|
| 789 |
+
<div class="result-card" style="color:#000;">
|
| 790 |
+
<h3 style="color:#000;font-weight:700;">Reference Class Images</h3>
|
| 791 |
+
<p style="color:#000;">Run Finer-CAM to retrieve representative CUB images for the reference classes.</p>
|
| 792 |
</div>
|
| 793 |
"""
|
| 794 |
)
|
|
|
|
| 799 |
):
|
| 800 |
prediction_report = gr.HTML(
|
| 801 |
"""
|
| 802 |
+
<div class="result-card" style="color:#000;">
|
| 803 |
+
<h3 style="color:#000;font-weight:700;">Prediction Summary</h3>
|
| 804 |
+
<p style="color:#000;">Run Finer-CAM to see the predicted class, top predictions, and reference classes.</p>
|
| 805 |
</div>
|
| 806 |
"""
|
| 807 |
)
|