Godreign commited on
Commit
3bdd51c
Β·
verified Β·
1 Parent(s): 4c73f8b

removed suggestions

Browse files
Files changed (1) hide show
  1. app.py +17 -42
app.py CHANGED
@@ -345,33 +345,15 @@ def get_class_specific_attention(image, model_name, class_query):
345
 
346
 
347
  # ---------------------------
348
- # Get Class Suggestions
349
  # ---------------------------
350
- def get_class_suggestions(query, model_name):
351
- try:
352
- if not query or len(query.strip()) < 2:
353
- return gr.Dropdown(choices=[], value=None)
354
-
355
- query_lower = query.lower().strip()
356
- suggestions = []
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="Start typing to see suggestions"
420
  )
421
- class_suggestions = gr.Dropdown(
422
- label="πŸ’‘ Suggestions (click to use)",
423
- choices=[],
424
- interactive=True,
425
- allow_custom_value=False
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
- # Update suggestions as user types
449
- class_input.change(
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=[class_suggestions],
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