removed suggestions
Browse files
app.py
CHANGED
|
@@ -345,33 +345,15 @@ def get_class_specific_attention(image, model_name, class_query):
|
|
| 345 |
|
| 346 |
|
| 347 |
# ---------------------------
|
| 348 |
-
#
|
| 349 |
# ---------------------------
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
model, extractor = load_model(model_name)
|
| 359 |
-
|
| 360 |
-
if MODEL_CONFIGS[model_name]["type"] == "hf":
|
| 361 |
-
labels = list(model.config.id2label.values())
|
| 362 |
-
else:
|
| 363 |
-
labels = IMAGENET_LABELS
|
| 364 |
-
|
| 365 |
-
for label in labels:
|
| 366 |
-
if query_lower in label.lower():
|
| 367 |
-
suggestions.append(label)
|
| 368 |
-
if len(suggestions) >= 10: # Limit to 10 suggestions
|
| 369 |
-
break
|
| 370 |
-
|
| 371 |
-
return gr.Dropdown(choices=suggestions, value=None)
|
| 372 |
-
except Exception as e:
|
| 373 |
-
print(f"Error getting suggestions: {e}")
|
| 374 |
-
return gr.Dropdown(choices=[], value=None)
|
| 375 |
|
| 376 |
|
| 377 |
# ---------------------------
|
|
@@ -416,13 +398,13 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 416 |
class_input = gr.Textbox(
|
| 417 |
label="π Enter Class Name",
|
| 418 |
placeholder="e.g., cat, dog, car, pizza...",
|
| 419 |
-
info="
|
| 420 |
)
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
choices=
|
| 424 |
-
|
| 425 |
-
|
| 426 |
)
|
| 427 |
class_button = gr.Button("π― Generate Class-Specific Attention", variant="primary")
|
| 428 |
|
|
@@ -445,17 +427,10 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 445 |
outputs=[output_label, output_image, processed_image]
|
| 446 |
)
|
| 447 |
|
| 448 |
-
#
|
| 449 |
-
|
| 450 |
-
get_class_suggestions,
|
| 451 |
-
inputs=[class_input, model_dropdown],
|
| 452 |
-
outputs=[class_suggestions]
|
| 453 |
-
)
|
| 454 |
-
|
| 455 |
-
# When user selects from suggestions, update the text input
|
| 456 |
-
class_suggestions.select(
|
| 457 |
lambda x: x,
|
| 458 |
-
inputs=[
|
| 459 |
outputs=[class_input]
|
| 460 |
)
|
| 461 |
|
|
|
|
| 345 |
|
| 346 |
|
| 347 |
# ---------------------------
|
| 348 |
+
# Sample Classes
|
| 349 |
# ---------------------------
|
| 350 |
+
SAMPLE_CLASSES = [
|
| 351 |
+
"cat", "dog", "tiger", "lion", "elephant",
|
| 352 |
+
"car", "truck", "airplane", "ship", "train",
|
| 353 |
+
"pizza", "hamburger", "coffee", "banana", "apple",
|
| 354 |
+
"chair", "table", "laptop", "keyboard", "mouse",
|
| 355 |
+
"person", "bicycle", "building", "tree", "flower"
|
| 356 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
|
| 358 |
|
| 359 |
# ---------------------------
|
|
|
|
| 398 |
class_input = gr.Textbox(
|
| 399 |
label="π Enter Class Name",
|
| 400 |
placeholder="e.g., cat, dog, car, pizza...",
|
| 401 |
+
info="Type any ImageNet class name"
|
| 402 |
)
|
| 403 |
+
gr.Markdown("**π‘ Sample classes to try:**")
|
| 404 |
+
sample_buttons = gr.Radio(
|
| 405 |
+
choices=SAMPLE_CLASSES,
|
| 406 |
+
label="Click to auto-fill",
|
| 407 |
+
interactive=True
|
| 408 |
)
|
| 409 |
class_button = gr.Button("π― Generate Class-Specific Attention", variant="primary")
|
| 410 |
|
|
|
|
| 427 |
outputs=[output_label, output_image, processed_image]
|
| 428 |
)
|
| 429 |
|
| 430 |
+
# When user selects a sample class, update the text input
|
| 431 |
+
sample_buttons.change(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
lambda x: x,
|
| 433 |
+
inputs=[sample_buttons],
|
| 434 |
outputs=[class_input]
|
| 435 |
)
|
| 436 |
|