Spaces:
Running
Running
feat: enhance visual display of detected faces with improved layout and image rendering
Browse files- web/interface.py +19 -15
web/interface.py
CHANGED
|
@@ -131,6 +131,12 @@ class WebInterface:
|
|
| 131 |
border-radius: 8px;
|
| 132 |
margin-bottom: 24px;
|
| 133 |
border: 1px solid #4a4a4a;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
}
|
| 135 |
.face-info h3 {
|
| 136 |
color: #ffffff;
|
|
@@ -250,12 +256,20 @@ class WebInterface:
|
|
| 250 |
face_confidence = face_result['confidence']
|
| 251 |
performers = face_result['performers']
|
| 252 |
|
|
|
|
|
|
|
|
|
|
| 253 |
html_parts.append(f"""
|
| 254 |
<div class="performer-card">
|
| 255 |
<div class="face-info">
|
| 256 |
-
<
|
| 257 |
-
|
| 258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
</div>
|
| 260 |
""")
|
| 261 |
|
|
@@ -368,26 +382,16 @@ class WebInterface:
|
|
| 368 |
label="Performer Information",
|
| 369 |
value="<p>Upload an image and click search to see results.</p>"
|
| 370 |
)
|
| 371 |
-
face_gallery = gr.Gallery(
|
| 372 |
-
label="Detected Faces",
|
| 373 |
-
show_label=True,
|
| 374 |
-
elem_id="face-gallery",
|
| 375 |
-
columns=4,
|
| 376 |
-
rows=2,
|
| 377 |
-
height=300,
|
| 378 |
-
object_fit="contain",
|
| 379 |
-
allow_preview=True
|
| 380 |
-
)
|
| 381 |
|
| 382 |
def visual_search_wrapper(img, threshold, results):
|
| 383 |
"""Wrapper that returns only visual components"""
|
| 384 |
json_results, gallery_images, html_content = self.multiple_image_search_with_visual(img, threshold, results)
|
| 385 |
-
return html_content
|
| 386 |
|
| 387 |
search_btn.click(
|
| 388 |
fn=visual_search_wrapper,
|
| 389 |
inputs=[img_input, threshold, results_count],
|
| 390 |
-
outputs=[performer_info
|
| 391 |
api_name="multiple_image_search_with_visual"
|
| 392 |
)
|
| 393 |
|
|
|
|
| 131 |
border-radius: 8px;
|
| 132 |
margin-bottom: 24px;
|
| 133 |
border: 1px solid #4a4a4a;
|
| 134 |
+
display: flex;
|
| 135 |
+
align-items: flex-start;
|
| 136 |
+
gap: 20px;
|
| 137 |
+
}
|
| 138 |
+
.face-info-content {
|
| 139 |
+
flex: 1;
|
| 140 |
}
|
| 141 |
.face-info h3 {
|
| 142 |
color: #ffffff;
|
|
|
|
| 256 |
face_confidence = face_result['confidence']
|
| 257 |
performers = face_result['performers']
|
| 258 |
|
| 259 |
+
# Create base64 data URL for the detected face image
|
| 260 |
+
face_image_b64 = f"data:image/jpeg;base64,{face_result['image']}"
|
| 261 |
+
|
| 262 |
html_parts.append(f"""
|
| 263 |
<div class="performer-card">
|
| 264 |
<div class="face-info">
|
| 265 |
+
<div class="detected-face">
|
| 266 |
+
<img src="{face_image_b64}" alt="Detected Face {i+1}" style="width: 120px; height: 120px; border-radius: 12px; object-fit: cover; border: 2px solid #569cd6; box-shadow: 0 4px 12px rgba(0,0,0,0.3);">
|
| 267 |
+
</div>
|
| 268 |
+
<div class="face-info-content">
|
| 269 |
+
<h3>Face {i+1}</h3>
|
| 270 |
+
<p><strong>Detection Confidence:</strong> {face_confidence:.1%}</p>
|
| 271 |
+
<p><strong>Matches Found:</strong> {len(performers)}</p>
|
| 272 |
+
</div>
|
| 273 |
</div>
|
| 274 |
""")
|
| 275 |
|
|
|
|
| 382 |
label="Performer Information",
|
| 383 |
value="<p>Upload an image and click search to see results.</p>"
|
| 384 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
|
| 386 |
def visual_search_wrapper(img, threshold, results):
|
| 387 |
"""Wrapper that returns only visual components"""
|
| 388 |
json_results, gallery_images, html_content = self.multiple_image_search_with_visual(img, threshold, results)
|
| 389 |
+
return html_content
|
| 390 |
|
| 391 |
search_btn.click(
|
| 392 |
fn=visual_search_wrapper,
|
| 393 |
inputs=[img_input, threshold, results_count],
|
| 394 |
+
outputs=[performer_info],
|
| 395 |
api_name="multiple_image_search_with_visual"
|
| 396 |
)
|
| 397 |
|