Spaces:
Sleeping
Sleeping
Saptadip Saha commited on
Commit Β·
7f7fa37
1
Parent(s): 3b0d838
fix: use DataFrame for chart, fix blank score cells
Browse files
app.py
CHANGED
|
@@ -94,7 +94,8 @@ text_input = (
|
|
| 94 |
"a cat, a dog, a car, a person walking, "
|
| 95 |
"a sunset, a building, a flower, an animal"
|
| 96 |
)
|
| 97 |
-
|
|
|
|
| 98 |
score_df = pd.DataFrame(columns=["Rank", "Label", "Score (%)"])
|
| 99 |
status_msg = "Upload an image and click **Analyze** to begin."
|
| 100 |
top_label = ""
|
|
@@ -158,11 +159,12 @@ def analyze(state: State):
|
|
| 158 |
|
| 159 |
state.top_label = labels[0]
|
| 160 |
state.top_score = scores[0]
|
| 161 |
-
state.
|
| 162 |
-
state.
|
|
|
|
| 163 |
"Rank": list(range(1, len(labels) + 1)),
|
| 164 |
"Label": labels,
|
| 165 |
-
"Score (%)": scores,
|
| 166 |
})
|
| 167 |
state.has_results = True
|
| 168 |
state.status_msg = f"β
Top match: **{labels[0]}** ({scores[0]:.1f}%)"
|
|
@@ -178,14 +180,14 @@ def analyze(state: State):
|
|
| 178 |
def reset(state: State):
|
| 179 |
state.uploaded_image = None
|
| 180 |
state.display_image = None
|
| 181 |
-
state.
|
|
|
|
| 182 |
state.score_df = pd.DataFrame(columns=["Rank", "Label", "Score (%)"])
|
| 183 |
state.top_label = ""
|
| 184 |
state.top_score = 0.0
|
| 185 |
state.has_results = False
|
| 186 |
state.status_msg = "Upload a new image and click Analyze."
|
| 187 |
|
| 188 |
-
|
| 189 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 190 |
# PAGE β DEMO
|
| 191 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -241,7 +243,7 @@ demo_md = """
|
|
| 241 |
|>
|
| 242 |
|>
|
| 243 |
|
| 244 |
-
<|{
|
| 245 |
|
| 246 |
<|part|render={has_results}|class_name=score-table|
|
| 247 |
**Detailed Scores:**
|
|
@@ -259,7 +261,7 @@ demo_md = """
|
|
| 259 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 260 |
about_md = """
|
| 261 |
<|part|class_name=page-header|
|
| 262 |
-
# π§ About VisionQuery
|
| 263 |
### Problem Β· Solution Β· Technology Stack
|
| 264 |
|>
|
| 265 |
|
|
@@ -293,50 +295,6 @@ This makes vision AI **slow, costly, and inflexible** for real-world deployment.
|
|
| 293 |
|
| 294 |
---
|
| 295 |
|
| 296 |
-
## π¬ How SigLIP Works
|
| 297 |
-
|
| 298 |
-
<|layout|columns=1 1 1|gap=1.5rem|
|
| 299 |
-
|
| 300 |
-
<|part|class_name=card tech-card|
|
| 301 |
-
### πΌοΈ Image Encoder
|
| 302 |
-
Vision Transformer (ViT) encodes the
|
| 303 |
-
uploaded image into a dense embedding
|
| 304 |
-
vector in a shared vision-language space.
|
| 305 |
-
|>
|
| 306 |
-
|
| 307 |
-
<|part|class_name=card tech-card|
|
| 308 |
-
### π Text Encoder
|
| 309 |
-
BERT-style transformer encodes each
|
| 310 |
-
label into an embedding in the same
|
| 311 |
-
shared space.
|
| 312 |
-
|>
|
| 313 |
-
|
| 314 |
-
<|part|class_name=card tech-card|
|
| 315 |
-
### π― Sigmoid Scoring
|
| 316 |
-
Unlike CLIP (softmax), SigLIP applies
|
| 317 |
-
**sigmoid loss** β each pair is scored
|
| 318 |
-
independently, giving better calibration.
|
| 319 |
-
|>
|
| 320 |
-
|
| 321 |
-
|>
|
| 322 |
-
|
| 323 |
-
---
|
| 324 |
-
|
| 325 |
-
## βοΈ SigLIP vs CLIP
|
| 326 |
-
|
| 327 |
-
<|layout|columns=1 1|gap=2rem|
|
| 328 |
-
|
| 329 |
-
<|part|class_name=card|
|
| 330 |
-
| Feature | CLIP | SigLIP β
|
|
| 331 |
-
|---|---|---|
|
| 332 |
-
| Loss Function | Softmax | Sigmoid |
|
| 333 |
-
| Multi-label | β | β
|
|
| 334 |
-
| Multilingual | β | β
|
|
| 335 |
-
| Score Calibration | Lower | Higher |
|
| 336 |
-
| ImageNet Accuracy | Good | Better |
|
| 337 |
-
|>
|
| 338 |
-
|
| 339 |
-
<|part|class_name=card|
|
| 340 |
### π οΈ Tech Stack
|
| 341 |
|
| 342 |
**Model Layer**
|
|
@@ -355,56 +313,6 @@ Hugging Face Spaces (Docker)
|
|
| 355 |
|
| 356 |
---
|
| 357 |
|
| 358 |
-
## π Real-World Applications
|
| 359 |
-
|
| 360 |
-
<|layout|columns=1 1 1|gap=1rem|
|
| 361 |
-
|
| 362 |
-
<|part|class_name=card use-card|
|
| 363 |
-
### π₯ Medical Imaging
|
| 364 |
-
Describe symptoms in text β instantly
|
| 365 |
-
find matching scan categories without
|
| 366 |
-
training a custom classifier.
|
| 367 |
-
|>
|
| 368 |
-
|
| 369 |
-
<|part|class_name=card use-card|
|
| 370 |
-
### π E-Commerce Search
|
| 371 |
-
Enable natural language product search
|
| 372 |
-
across image catalogues β "red floral
|
| 373 |
-
dress with short sleeves".
|
| 374 |
-
|>
|
| 375 |
-
|
| 376 |
-
<|part|class_name=card use-card|
|
| 377 |
-
### π Security & Safety
|
| 378 |
-
Detect unusual scenes using plain text
|
| 379 |
-
descriptions β "person near restricted
|
| 380 |
-
area", "fire or smoke".
|
| 381 |
-
|>
|
| 382 |
-
|
| 383 |
-
<|part|class_name=card use-card|
|
| 384 |
-
### π¨ Digital Asset Mgmt
|
| 385 |
-
Auto-tag, search and organise large image
|
| 386 |
-
libraries using any text query β no
|
| 387 |
-
manual labelling required.
|
| 388 |
-
|>
|
| 389 |
-
|
| 390 |
-
<|part|class_name=card use-card|
|
| 391 |
-
### βΏ Accessibility
|
| 392 |
-
Automatically describe image content
|
| 393 |
-
for visually impaired users using the
|
| 394 |
-
model's strongest text matches.
|
| 395 |
-
|>
|
| 396 |
-
|
| 397 |
-
<|part|class_name=card use-card|
|
| 398 |
-
### π¬ Scientific Research
|
| 399 |
-
Classify microscopy, satellite, or
|
| 400 |
-
sensor imagery with expert text
|
| 401 |
-
descriptions οΏ½οΏ½οΏ½ no ML expertise needed.
|
| 402 |
-
|>
|
| 403 |
-
|
| 404 |
-
|>
|
| 405 |
-
|
| 406 |
-
---
|
| 407 |
-
|
| 408 |
## π Citation
|
| 409 |
|
| 410 |
> Zhai, X. et al. (2023). *Sigmoid Loss for Language Image Pre-Training.*
|
|
|
|
| 94 |
"a cat, a dog, a car, a person walking, "
|
| 95 |
"a sunset, a building, a flower, an animal"
|
| 96 |
)
|
| 97 |
+
chart_data = pd.DataFrame({"Label": [], "Score": []})
|
| 98 |
+
chart_empty = True
|
| 99 |
score_df = pd.DataFrame(columns=["Rank", "Label", "Score (%)"])
|
| 100 |
status_msg = "Upload an image and click **Analyze** to begin."
|
| 101 |
top_label = ""
|
|
|
|
| 159 |
|
| 160 |
state.top_label = labels[0]
|
| 161 |
state.top_score = scores[0]
|
| 162 |
+
state.chart_data = pd.DataFrame({"Label": labels, "Score (%)": scores})
|
| 163 |
+
state.chart_empty = False
|
| 164 |
+
state.score_df = pd.DataFrame({
|
| 165 |
"Rank": list(range(1, len(labels) + 1)),
|
| 166 |
"Label": labels,
|
| 167 |
+
"Score (%)": [f"{s:.2f}" for s in scores], # β string, never blank
|
| 168 |
})
|
| 169 |
state.has_results = True
|
| 170 |
state.status_msg = f"β
Top match: **{labels[0]}** ({scores[0]:.1f}%)"
|
|
|
|
| 180 |
def reset(state: State):
|
| 181 |
state.uploaded_image = None
|
| 182 |
state.display_image = None
|
| 183 |
+
state.chart_data = pd.DataFrame({"Label": [], "Score (%)": []})
|
| 184 |
+
state.chart_empty = True
|
| 185 |
state.score_df = pd.DataFrame(columns=["Rank", "Label", "Score (%)"])
|
| 186 |
state.top_label = ""
|
| 187 |
state.top_score = 0.0
|
| 188 |
state.has_results = False
|
| 189 |
state.status_msg = "Upload a new image and click Analyze."
|
| 190 |
|
|
|
|
| 191 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 192 |
# PAGE β DEMO
|
| 193 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 243 |
|>
|
| 244 |
|>
|
| 245 |
|
| 246 |
+
<|{chart_data}|chart|type=bar|x=Score (%)|y=Label|orientation=h|title=SigLIP Similarity Scores|height=350px|>
|
| 247 |
|
| 248 |
<|part|render={has_results}|class_name=score-table|
|
| 249 |
**Detailed Scores:**
|
|
|
|
| 261 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 262 |
about_md = """
|
| 263 |
<|part|class_name=page-header|
|
| 264 |
+
# π§ About VisionQuery
|
| 265 |
### Problem Β· Solution Β· Technology Stack
|
| 266 |
|>
|
| 267 |
|
|
|
|
| 295 |
|
| 296 |
---
|
| 297 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
### π οΈ Tech Stack
|
| 299 |
|
| 300 |
**Model Layer**
|
|
|
|
| 313 |
|
| 314 |
---
|
| 315 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
## π Citation
|
| 317 |
|
| 318 |
> Zhai, X. et al. (2023). *Sigmoid Loss for Language Image Pre-Training.*
|