turhancan97 commited on
Commit
2f776bc
·
verified ·
1 Parent(s): b1c778c

Upload folder using huggingface_hub

Browse files
app.py CHANGED
@@ -51,7 +51,24 @@ ADAPTER_TASKS = [t for t in TASKS if not t.is_base]
51
  ADAPTER_CHOICES = [(t.display_name, t.key) for t in ADAPTER_TASKS]
52
 
53
  EXAMPLES_DIR = Path(__file__).parent / "examples"
54
- EXAMPLE_IMAGES = sorted(str(p) for p in EXAMPLES_DIR.glob("*.jpg")) if EXAMPLES_DIR.exists() else []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
 
57
  def _to_inputs(image):
@@ -132,14 +149,14 @@ with gr.Blocks(title="ViT + LoRA image classifier", theme=gr.themes.Soft()) as d
132
  with gr.Column(scale=1):
133
  output = gr.Label(num_top_classes=10, label="Predictions")
134
 
135
- if EXAMPLE_IMAGES:
136
  gr.Examples(
137
- examples=[[p, BASE_TASK_NAME, 5, 0.0] for p in EXAMPLE_IMAGES],
138
  inputs=[image, task, top_k, threshold],
139
  outputs=output,
140
  fn=classify,
141
  cache_examples=False,
142
- label="Example images",
143
  )
144
 
145
  classify_args = dict(fn=classify, inputs=[image, task, top_k, threshold], outputs=output)
 
51
  ADAPTER_CHOICES = [(t.display_name, t.key) for t in ADAPTER_TASKS]
52
 
53
  EXAMPLES_DIR = Path(__file__).parent / "examples"
54
+
55
+ FOOD_NAMES = {"baklava", "donut", "dumplings", "hotdog"}
56
+ FOOD_TASK_KEY = "food101" if any(t.key == "food101" for t in TASKS) else BASE_TASK_NAME
57
+
58
+
59
+ def _collect_examples() -> list[tuple[str, str]]:
60
+ """Return (path, default_task_key) pairs for each example image."""
61
+ if not EXAMPLES_DIR.exists():
62
+ return []
63
+ pairs = []
64
+ for p in sorted(EXAMPLES_DIR.glob("*.jpg")):
65
+ task_key = FOOD_TASK_KEY if p.stem.lower() in FOOD_NAMES else BASE_TASK_NAME
66
+ pairs.append((str(p), task_key))
67
+ return pairs
68
+
69
+
70
+ EXAMPLE_PAIRS = _collect_examples()
71
+ EXAMPLE_IMAGES = [p for p, _ in EXAMPLE_PAIRS]
72
 
73
 
74
  def _to_inputs(image):
 
149
  with gr.Column(scale=1):
150
  output = gr.Label(num_top_classes=10, label="Predictions")
151
 
152
+ if EXAMPLE_PAIRS:
153
  gr.Examples(
154
+ examples=[[p, tk, 5, 0.0] for p, tk in EXAMPLE_PAIRS],
155
  inputs=[image, task, top_k, threshold],
156
  outputs=output,
157
  fn=classify,
158
  cache_examples=False,
159
+ label="Example images (animals default to ImageNet, foods to Food-101)",
160
  )
161
 
162
  classify_args = dict(fn=classify, inputs=[image, task, top_k, threshold], outputs=output)
examples/baklava.jpg ADDED
examples/donut.jpg ADDED
examples/dumplings.jpg ADDED
examples/hotdog.jpg ADDED