Darius Morawiec commited on
Commit
3d8d21b
·
1 Parent(s): bfa4ccc

Use constants for the default system prompt and examples

Browse files
Files changed (1) hide show
  1. app.py +50 -50
app.py CHANGED
@@ -45,6 +45,54 @@ MODEL_IDS = [
45
  "Qwen/Qwen3-VL-8B-Instruct", # https://huggingface.co/Qwen/Qwen3-VL-8B-Instruct
46
  "Qwen/Qwen3-VL-32B-Instruct", # https://huggingface.co/Qwen/Qwen3-VL-32B-Instruct
47
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
  # Global variables to track loaded model
50
  current_model = None
@@ -111,11 +159,10 @@ with gr.Blocks() as demo:
111
  choices=MODEL_IDS,
112
  label="✨ Select Model ID",
113
  )
114
- default_system_prompt = 'You are a helpful assistant to detect objects in images. When asked to detect elements based on a description, you return a valid JSON object containing bounding boxes for all elements in the form `[{"bbox_2d": [xmin, ymin, xmax, ymax], "label": "placeholder"}, ...]`. For example, a valid response could be: `[{"bbox_2d": [10, 30, 20, 60], "label": "placeholder"}, {"bbox_2d": [40, 15, 52, 27], "label": "placeholder"}]`.'
115
  system_prompt = gr.Textbox(
116
  label="System Prompt",
117
  lines=3,
118
- value=default_system_prompt,
119
  )
120
  default_user_prompt = "detect object"
121
  user_prompt = gr.Textbox(
@@ -320,54 +367,7 @@ with gr.Blocks() as demo:
320
  cache_examples=True,
321
  cache_mode="eager",
322
  run_on_click=True,
323
- examples=[
324
- [
325
- EXAMPLES_DIR
326
- / "niklas-ohlrogge-niamoh-de-fDYRfHoRC4k-unsplash.jpg",
327
- "Qwen/Qwen3-VL-4B-Instruct",
328
- default_system_prompt,
329
- "detect sailboat, rowboat, person",
330
- 512,
331
- "Yes",
332
- 1920,
333
- ],
334
- [
335
- EXAMPLES_DIR / "elevate-nYgy58eb9aw-unsplash.jpg",
336
- "Qwen/Qwen3-VL-4B-Instruct",
337
- default_system_prompt,
338
- "detect shirt, jeans, jacket, skirt, sunglasses, earring, drink",
339
- 1024,
340
- "Yes",
341
- 1920,
342
- ],
343
- [
344
- EXAMPLES_DIR / "markus-spiske-oPDQGXW7i40-unsplash.jpg",
345
- "Qwen/Qwen3-VL-4B-Instruct",
346
- default_system_prompt,
347
- "detect basketball, player with white jersey, player with black jersey",
348
- 512,
349
- "Yes",
350
- 1920,
351
- ],
352
- [
353
- EXAMPLES_DIR / "william-hook-9e9PD9blAto-unsplash.jpg",
354
- "Qwen/Qwen3-VL-4B-Instruct",
355
- default_system_prompt,
356
- "detect app to find great places, app to take beautiful photos, app to listen music",
357
- 512,
358
- "Yes",
359
- 1920,
360
- ],
361
- [
362
- EXAMPLES_DIR / "tasso-mitsarakis-dw7Y4W6Rhmk-unsplash.jpg",
363
- "Qwen/Qwen3-VL-4B-Instruct",
364
- default_system_prompt,
365
- "detect person, bicycle, netherlands flag",
366
- 1920,
367
- "Yes",
368
- 1920,
369
- ],
370
- ],
371
  inputs=[
372
  image_input,
373
  input_model_id,
 
45
  "Qwen/Qwen3-VL-8B-Instruct", # https://huggingface.co/Qwen/Qwen3-VL-8B-Instruct
46
  "Qwen/Qwen3-VL-32B-Instruct", # https://huggingface.co/Qwen/Qwen3-VL-32B-Instruct
47
  ]
48
+ DEFAULT_SYSTEM_PROMPT = 'You are a helpful assistant to detect objects in images. When asked to detect elements based on a description, you return a valid JSON object containing bounding boxes for all elements in the form `[{"bbox_2d": [xmin, ymin, xmax, ymax], "label": "placeholder"}, ...]`. For example, a valid response could be: `[{"bbox_2d": [10, 30, 20, 60], "label": "placeholder"}, {"bbox_2d": [40, 15, 52, 27], "label": "placeholder"}]`.'
49
+ EXAMPLES = [
50
+ [
51
+ EXAMPLES_DIR / "niklas-ohlrogge-niamoh-de-fDYRfHoRC4k-unsplash.jpg",
52
+ "Qwen/Qwen3-VL-4B-Instruct",
53
+ DEFAULT_SYSTEM_PROMPT,
54
+ "detect sailboat, rowboat, person",
55
+ 512,
56
+ "Yes",
57
+ 1920,
58
+ ],
59
+ [
60
+ EXAMPLES_DIR / "elevate-nYgy58eb9aw-unsplash.jpg",
61
+ "Qwen/Qwen3-VL-4B-Instruct",
62
+ DEFAULT_SYSTEM_PROMPT,
63
+ "detect shirt, jeans, jacket, skirt, sunglasses, earring, drink",
64
+ 1024,
65
+ "Yes",
66
+ 1920,
67
+ ],
68
+ [
69
+ EXAMPLES_DIR / "markus-spiske-oPDQGXW7i40-unsplash.jpg",
70
+ "Qwen/Qwen3-VL-4B-Instruct",
71
+ DEFAULT_SYSTEM_PROMPT,
72
+ "detect basketball, player with white jersey, player with black jersey",
73
+ 512,
74
+ "Yes",
75
+ 1920,
76
+ ],
77
+ [
78
+ EXAMPLES_DIR / "william-hook-9e9PD9blAto-unsplash.jpg",
79
+ "Qwen/Qwen3-VL-4B-Instruct",
80
+ DEFAULT_SYSTEM_PROMPT,
81
+ "detect app to find great places, app to take beautiful photos, app to listen music",
82
+ 512,
83
+ "Yes",
84
+ 1920,
85
+ ],
86
+ [
87
+ EXAMPLES_DIR / "tasso-mitsarakis-dw7Y4W6Rhmk-unsplash.jpg",
88
+ "Qwen/Qwen3-VL-4B-Instruct",
89
+ DEFAULT_SYSTEM_PROMPT,
90
+ "detect person, bicycle, netherlands flag",
91
+ 1920,
92
+ "Yes",
93
+ 1920,
94
+ ],
95
+ ]
96
 
97
  # Global variables to track loaded model
98
  current_model = None
 
159
  choices=MODEL_IDS,
160
  label="✨ Select Model ID",
161
  )
 
162
  system_prompt = gr.Textbox(
163
  label="System Prompt",
164
  lines=3,
165
+ value=DEFAULT_SYSTEM_PROMPT,
166
  )
167
  default_user_prompt = "detect object"
168
  user_prompt = gr.Textbox(
 
367
  cache_examples=True,
368
  cache_mode="eager",
369
  run_on_click=True,
370
+ examples=EXAMPLES,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
371
  inputs=[
372
  image_input,
373
  input_model_id,