bla commited on
Commit
0010667
·
verified ·
1 Parent(s): 9c4d474

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +172 -153
app.py CHANGED
@@ -8,25 +8,137 @@ import matplotlib.pyplot as plt
8
  from transformers import AutoModel, AutoProcessor
9
  from ultralytics import YOLO
10
 
11
- # Custom CSS for NextUI inspired look
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  custom_css = """
13
  :root {
14
  --primary: #0070f3;
15
  --primary-foreground: #ffffff;
16
- --secondary: #7928ca;
17
- --background: #fafafa;
18
  --card: #ffffff;
19
  --card-foreground: #111111;
20
  --border: #eaeaea;
21
  --ring: #0070f3;
22
- --shadow: 0 4px 14px 0 rgba(0, 118, 255, 0.2);
23
- --radius: 0.75rem;
24
  }
25
 
26
  .dark {
27
  --primary: #0070f3;
28
  --primary-foreground: #ffffff;
29
- --secondary: #9353d3;
30
  --background: #000000;
31
  --card: #111111;
32
  --card-foreground: #ffffff;
@@ -43,31 +155,27 @@ custom_css = """
43
  .main-container {
44
  background-color: var(--background);
45
  padding: 2rem;
46
- min-height: 100vh;
47
  }
48
 
49
  .header {
50
- margin-bottom: 2.5rem;
51
  text-align: center;
52
  }
53
 
54
  .header h1 {
55
- font-size: 3rem;
56
  font-weight: 800;
57
  color: var(--card-foreground);
58
- margin-bottom: 0.75rem;
59
- background: linear-gradient(to right, var(--primary), var(--secondary));
60
  -webkit-background-clip: text;
61
  -webkit-text-fill-color: transparent;
62
- letter-spacing: -0.025em;
63
  }
64
 
65
  .header p {
66
  color: var(--card-foreground);
67
  opacity: 0.8;
68
- font-size: 1.2rem;
69
- max-width: 600px;
70
- margin: 0 auto;
71
  }
72
 
73
  .tab-nav {
@@ -76,67 +184,57 @@ custom_css = """
76
  padding: 0.5rem;
77
  margin-bottom: 2rem;
78
  box-shadow: var(--shadow);
79
- overflow: hidden;
80
  }
81
 
82
  .tab-nav button {
83
- border-radius: calc(var(--radius) - 0.25rem) !important;
84
  font-weight: 600 !important;
85
- transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
86
  padding: 0.75rem 1.5rem !important;
87
- margin: 0.25rem !important;
88
  }
89
 
90
  .tab-nav button.selected {
91
- background: linear-gradient(to right, var(--primary), var(--secondary)) !important;
92
  color: var(--primary-foreground) !important;
93
- transform: translateY(-1px);
94
- box-shadow: 0 4px 14px 0 rgba(0, 118, 255, 0.3);
95
  }
96
 
97
  .input-panel, .output-panel {
98
  background-color: var(--card);
99
  border-radius: var(--radius);
100
- padding: 1.75rem;
101
  box-shadow: var(--shadow);
102
  height: 100%;
103
  display: flex;
104
  flex-direction: column;
105
- transition: transform 0.2s ease, box-shadow 0.2s ease;
106
- }
107
-
108
- .input-panel:hover, .output-panel:hover {
109
- transform: translateY(-2px);
110
- box-shadow: 0 6px 20px rgba(0, 118, 255, 0.25);
111
  }
112
 
113
  .input-panel h3, .output-panel h3 {
114
  font-size: 1.25rem;
115
  font-weight: 600;
116
- margin-bottom: 1.25rem;
117
  color: var(--card-foreground);
118
- border-bottom: 2px solid;
119
- border-image: linear-gradient(to right, var(--primary), var(--secondary)) 1;
120
  padding-bottom: 0.5rem;
121
  display: inline-block;
122
  }
123
 
124
  .gr-button-primary {
125
- background: linear-gradient(to right, var(--primary), var(--secondary)) !important;
126
  color: var(--primary-foreground) !important;
127
  border-radius: var(--radius) !important;
128
  font-weight: 600 !important;
129
- transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
130
  padding: 0.75rem 1.5rem !important;
131
- box-shadow: 0 4px 14px 0 rgba(0, 118, 255, 0.3) !important;
132
  width: 100%;
133
- margin-top: 1.25rem;
134
- border: none !important;
135
  }
136
 
137
  .gr-button-primary:hover {
138
  transform: translateY(-2px) !important;
139
- box-shadow: 0 6px 20px rgba(0, 118, 255, 0.4) !important;
140
  }
141
 
142
  .gr-form {
@@ -148,14 +246,12 @@ custom_css = """
148
  border: 1px solid var(--border) !important;
149
  border-radius: var(--radius) !important;
150
  padding: 0.75rem 1rem !important;
151
- transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
152
- background-color: var(--card) !important;
153
  }
154
 
155
  .gr-input:focus, .gr-select:focus {
156
  border-color: var(--primary) !important;
157
  box-shadow: 0 0 0 2px rgba(0, 118, 255, 0.25) !important;
158
- outline: none !important;
159
  }
160
 
161
  .gr-panel {
@@ -166,88 +262,37 @@ custom_css = """
166
  border: 1px solid var(--border) !important;
167
  border-radius: var(--radius) !important;
168
  overflow: hidden;
169
- margin-top: 1rem;
170
- transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
171
- }
172
-
173
- .gr-accordion:hover {
174
- border-color: var(--primary) !important;
175
  }
176
 
177
  .footer {
178
- margin-top: 3rem;
179
  border-top: 1px solid var(--border);
180
- padding-top: 2rem;
181
- font-size: 0.95rem;
182
  color: var(--card-foreground);
183
- opacity: 0.8;
184
  text-align: center;
185
  }
186
 
187
  .footer-card {
188
  background-color: var(--card);
189
  border-radius: var(--radius);
190
- padding: 1.75rem;
191
  box-shadow: var(--shadow);
192
- transition: transform 0.2s ease, box-shadow 0.2s ease;
193
- }
194
-
195
- .footer-card:hover {
196
- transform: translateY(-2px);
197
- box-shadow: 0 6px 20px rgba(0, 118, 255, 0.25);
198
  }
199
 
200
  .tips-grid {
201
  display: grid;
202
- grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
203
- gap: 1.25rem;
204
- margin-top: 1.25rem;
205
  }
206
 
207
  .tip-card {
208
  background-color: var(--card);
209
  border-radius: var(--radius);
210
- padding: 1.25rem;
211
- border-left: 3px solid;
212
- border-image: linear-gradient(to bottom, var(--primary), var(--secondary)) 1 100%;
213
- transition: transform 0.2s ease, box-shadow 0.2s ease;
214
- box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
215
- }
216
-
217
- .tip-card:hover {
218
- transform: translateY(-2px);
219
- box-shadow: 0 4px 12px rgba(0, 118, 255, 0.15);
220
- }
221
-
222
- /* Image upload area styling */
223
- .image-container {
224
- border: 2px dashed var(--border);
225
- border-radius: var(--radius);
226
- padding: 1.5rem;
227
- text-align: center;
228
- transition: all 0.2s ease;
229
- }
230
-
231
- .image-container:hover {
232
- border-color: var(--primary);
233
- }
234
-
235
- /* Slider styling */
236
- input[type=range] {
237
- height: 6px;
238
- border-radius: 10px;
239
- background: linear-gradient(to right, var(--primary), var(--secondary)) !important;
240
- }
241
-
242
- input[type=range]::-webkit-slider-thumb {
243
- background: var(--primary) !important;
244
- border: 2px solid white;
245
- box-shadow: 0 2px 6px rgba(0, 118, 255, 0.3);
246
- }
247
-
248
- /* Loading animation */
249
- .gr-progress {
250
- background: linear-gradient(to right, var(--primary), var(--secondary)) !important;
251
  }
252
  """
253
 
@@ -467,10 +512,10 @@ def create_svg_from_detections(json_results, img_width, img_height):
467
  svg_header = f'<svg width="{img_width}" height="{img_height}" xmlns="http://www.w3.org/2000/svg">'
468
  svg_content = ""
469
 
470
- # NextUI-inspired color palette
471
  colors = [
472
- "#0070F3", "#7928CA", "#FF0080", "#50E3C2",
473
- "#F5A623", "#FF4D4D", "#0070F3", "#7928CA"
474
  ]
475
 
476
  for i, result in enumerate(json_results):
@@ -487,7 +532,7 @@ def create_svg_from_detections(json_results, img_width, img_height):
487
  # Select color based on class index
488
  color = colors[i % len(colors)]
489
 
490
- # Create rectangle element with rounded corners
491
  svg_content += f'''
492
  <rect
493
  x="{x:.2f}"
@@ -495,30 +540,17 @@ def create_svg_from_detections(json_results, img_width, img_height):
495
  width="{width:.2f}"
496
  height="{height:.2f}"
497
  stroke="{color}"
498
- stroke-width="2.5"
499
  fill="none"
500
- rx="4"
501
- ry="4"
502
  data-label="{label}"
503
  data-score="{score:.2f}"
504
  />
505
- <rect
506
- x="{x:.2f}"
507
- y="{y-24:.2f}"
508
- width="{min(width, len(label)*8 + 60):.2f}"
509
- height="24"
510
- fill="{color}"
511
- rx="4"
512
- ry="4"
513
- opacity="0.9"
514
- />
515
  <text
516
- x="{x+5:.2f}"
517
- y="{y-8:.2f}"
518
  font-family="Arial"
519
  font-size="12"
520
- font-weight="bold"
521
- fill="white"
522
  >{label} ({score:.2f})</text>'''
523
 
524
  svg_footer = "\n</svg>"
@@ -529,10 +561,10 @@ def create_svg_from_segmentation(json_results, img_width, img_height):
529
  svg_header = f'<svg width="{img_width}" height="{img_height}" xmlns="http://www.w3.org/2000/svg">'
530
  svg_content = ""
531
 
532
- # NextUI-inspired color palette
533
  colors = [
534
- "#0070F3", "#7928CA", "#FF0080", "#50E3C2",
535
- "#F5A623", "#FF4D4D", "#0070F3", "#7928CA"
536
  ]
537
 
538
  for i, result in enumerate(json_results):
@@ -553,7 +585,7 @@ def create_svg_from_segmentation(json_results, img_width, img_height):
553
  <polygon
554
  points="{points_str}"
555
  stroke="{color}"
556
- stroke-width="2.5"
557
  fill="{color}33"
558
  data-label="{label}"
559
  data-score="{score:.2f}"
@@ -573,29 +605,16 @@ def create_svg_from_segmentation(json_results, img_width, img_height):
573
  width="{width:.2f}"
574
  height="{height:.2f}"
575
  stroke="{color}"
576
- stroke-width="1.5"
577
  fill="none"
578
- rx="4"
579
- ry="4"
580
  stroke-dasharray="5,5"
581
  />
582
- <rect
583
- x="{x:.2f}"
584
- y="{y-24:.2f}"
585
- width="{min(width, len(label)*8 + 60):.2f}"
586
- height="24"
587
- fill="{color}"
588
- rx="4"
589
- ry="4"
590
- opacity="0.9"
591
- />
592
  <text
593
- x="{x+5:.2f}"
594
- y="{y-8:.2f}"
595
  font-family="Arial"
596
  font-size="12"
597
- font-weight="bold"
598
- fill="white"
599
  >{label} ({score:.2f})</text>'''
600
 
601
  svg_footer = "\n</svg>"
@@ -650,10 +669,10 @@ with gr.Blocks(title="YOLO Vision Suite", css=custom_css) as demo:
650
  with gr.Row(equal_height=True):
651
  with gr.Column(elem_classes="input-panel", scale=1):
652
  gr.Markdown("### Input")
653
- input_image = gr.Image(label="Upload Image", type="numpy", height=300, elem_classes="image-container")
654
  text_prompt = gr.Textbox(
655
  label="Text Prompt",
656
- placeholder="Enter objects to detect (e.g., person, car, dog)",
657
  value="person, car, dog",
658
  elem_classes="gr-input"
659
  )
@@ -671,7 +690,7 @@ with gr.Blocks(title="YOLO Vision Suite", css=custom_css) as demo:
671
  label="Model Size",
672
  elem_classes="gr-select"
673
  )
674
- detect_button = gr.Button("Detect Objects", elem_classes="gr-button-primary")
675
 
676
  with gr.Column(elem_classes="output-panel", scale=1):
677
  gr.Markdown("### Results")
@@ -689,7 +708,7 @@ with gr.Blocks(title="YOLO Vision Suite", css=custom_css) as demo:
689
  with gr.Row(equal_height=True):
690
  with gr.Column(elem_classes="input-panel", scale=1):
691
  gr.Markdown("### Input")
692
- seg_input_image = gr.Image(label="Upload Image", type="numpy", height=300, elem_classes="image-container")
693
  with gr.Row():
694
  seg_confidence = gr.Slider(
695
  minimum=0.1,
@@ -704,7 +723,7 @@ with gr.Blocks(title="YOLO Vision Suite", css=custom_css) as demo:
704
  label="Model Size",
705
  elem_classes="gr-select"
706
  )
707
- segment_button = gr.Button("Segment Image", elem_classes="gr-button-primary")
708
 
709
  with gr.Column(elem_classes="output-panel", scale=1):
710
  gr.Markdown("### Results")
@@ -723,19 +742,19 @@ with gr.Blocks(title="YOLO Vision Suite", css=custom_css) as demo:
723
  gr.Markdown("### Tips & Information")
724
  with gr.Row(elem_classes="tips-grid"):
725
  with gr.Column(elem_classes="tip-card"):
726
- gr.Markdown("**🔍 Detection**")
727
  gr.Markdown("Enter comma-separated text prompts to specify what objects to detect")
728
 
729
  with gr.Column(elem_classes="tip-card"):
730
- gr.Markdown("**🧩 Segmentation**")
731
  gr.Markdown("The model will identify and segment common objects automatically")
732
 
733
  with gr.Column(elem_classes="tip-card"):
734
- gr.Markdown("**⚙️ Models**")
735
  gr.Markdown("Larger models provide better accuracy but require more processing power")
736
 
737
  with gr.Column(elem_classes="tip-card"):
738
- gr.Markdown("**📊 Output**")
739
  gr.Markdown("JSON output provides coordinates as percentages, compatible with SVG")
740
 
741
  # Set up event handlers
 
8
  from transformers import AutoModel, AutoProcessor
9
  from ultralytics import YOLO
10
 
11
+ # Custom CSS for shadcn/Radix UI inspired look
12
+ custom_css = """
13
+ :root {
14
+ --primary: #0f172a;
15
+ --primary-foreground: #f8fafc;
16
+ --background: #f8fafc;
17
+ --card: #ffffff;
18
+ --card-foreground: #0f172a;
19
+ --border: #e2e8f0;
20
+ --ring: #94a3b8;
21
+ --radius: 0.5rem;
22
+ }
23
+
24
+ .dark {
25
+ --primary: #f8fafc;
26
+ --primary-foreground: #0f172a;
27
+ --background: #0f172a;
28
+ --card: #1e293b;
29
+ --card-foreground: #f8fafc;
30
+ --border: #334155;
31
+ --ring: #94a3b8;
32
+ }
33
+
34
+ .gradio-container {
35
+ margin: 0 !important;
36
+ padding: 0 !important;
37
+ max-width: 100% !important;
38
+ }
39
+
40
+ .main-container {
41
+ background-color: var(--background);
42
+ border-radius: var(--radius);
43
+ padding: 1.5rem;
44
+ }
45
+
46
+ .header {
47
+ margin-bottom: 1.5rem;
48
+ border-bottom: 1px solid var(--border);
49
+ padding-bottom: 1rem;
50
+ }
51
+
52
+ .header h1 {
53
+ font-size: 1.875rem;
54
+ font-weight: 700;
55
+ color: var(--primary);
56
+ margin-bottom: 0.5rem;
57
+ }
58
+
59
+ .header p {
60
+ color: var(--card-foreground);
61
+ opacity: 0.8;
62
+ }
63
+
64
+ .tab-nav {
65
+ background-color: var(--card);
66
+ border: 1px solid var(--border);
67
+ border-radius: var(--radius);
68
+ padding: 0.25rem;
69
+ margin-bottom: 1.5rem;
70
+ }
71
+
72
+ .tab-nav button {
73
+ border-radius: calc(var(--radius) - 0.25rem) !important;
74
+ font-weight: 500 !important;
75
+ transition: all 0.2s ease-in-out !important;
76
+ }
77
+
78
+ .tab-nav button.selected {
79
+ background-color: var(--primary) !important;
80
+ color: var(--primary-foreground) !important;
81
+ }
82
+
83
+ .input-panel, .output-panel {
84
+ background-color: var(--card);
85
+ border: 1px solid var(--border);
86
+ border-radius: var(--radius);
87
+ padding: 1.5rem;
88
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
89
+ }
90
+
91
+ .gr-button-primary {
92
+ background-color: var(--primary) !important;
93
+ color: var(--primary-foreground) !important;
94
+ border-radius: var(--radius) !important;
95
+ font-weight: 500 !important;
96
+ transition: all 0.2s ease-in-out !important;
97
+ }
98
+
99
+ .gr-button-primary:hover {
100
+ opacity: 0.9 !important;
101
+ }
102
+
103
+ .gr-form {
104
+ border: none !important;
105
+ background: transparent !important;
106
+ }
107
+
108
+ .gr-input, .gr-select {
109
+ border: 1px solid var(--border) !important;
110
+ border-radius: var(--radius) !important;
111
+ padding: 0.5rem 0.75rem !important;
112
+ }
113
+
114
+ .gr-panel {
115
+ border: none !important;
116
+ }
117
+
118
+ .footer {
119
+ margin-top: 1.5rem;
120
+ border-top: 1px solid var(--border);
121
+ padding-top: 1rem;
122
+ font-size: 0.875rem;
123
+ color: var(--card-foreground);
124
+ opacity: 0.7;
125
+ }"""
126
+ # Custom CSS for a more modern UI inspired by NextUI
127
  custom_css = """
128
  :root {
129
  --primary: #0070f3;
130
  --primary-foreground: #ffffff;
131
+ --background: #f5f5f5;
 
132
  --card: #ffffff;
133
  --card-foreground: #111111;
134
  --border: #eaeaea;
135
  --ring: #0070f3;
136
+ --shadow: 0 4px 14px 0 rgba(0, 118, 255, 0.1);
 
137
  }
138
 
139
  .dark {
140
  --primary: #0070f3;
141
  --primary-foreground: #ffffff;
 
142
  --background: #000000;
143
  --card: #111111;
144
  --card-foreground: #ffffff;
 
155
  .main-container {
156
  background-color: var(--background);
157
  padding: 2rem;
 
158
  }
159
 
160
  .header {
161
+ margin-bottom: 2rem;
162
  text-align: center;
163
  }
164
 
165
  .header h1 {
166
+ font-size: 2.5rem;
167
  font-weight: 800;
168
  color: var(--card-foreground);
169
+ margin-bottom: 0.5rem;
170
+ background: linear-gradient(to right, #0070f3, #00bfff);
171
  -webkit-background-clip: text;
172
  -webkit-text-fill-color: transparent;
 
173
  }
174
 
175
  .header p {
176
  color: var(--card-foreground);
177
  opacity: 0.8;
178
+ font-size: 1.1rem;
 
 
179
  }
180
 
181
  .tab-nav {
 
184
  padding: 0.5rem;
185
  margin-bottom: 2rem;
186
  box-shadow: var(--shadow);
 
187
  }
188
 
189
  .tab-nav button {
190
+ border-radius: var(--radius) !important;
191
  font-weight: 600 !important;
192
+ transition: all 0.2s ease-in-out !important;
193
  padding: 0.75rem 1.5rem !important;
 
194
  }
195
 
196
  .tab-nav button.selected {
197
+ background-color: var(--primary) !important;
198
  color: var(--primary-foreground) !important;
199
+ transform: translateY(-2px);
200
+ box-shadow: 0 4px 14px 0 rgba(0, 118, 255, 0.25);
201
  }
202
 
203
  .input-panel, .output-panel {
204
  background-color: var(--card);
205
  border-radius: var(--radius);
206
+ padding: 1.5rem;
207
  box-shadow: var(--shadow);
208
  height: 100%;
209
  display: flex;
210
  flex-direction: column;
 
 
 
 
 
 
211
  }
212
 
213
  .input-panel h3, .output-panel h3 {
214
  font-size: 1.25rem;
215
  font-weight: 600;
216
+ margin-bottom: 1rem;
217
  color: var(--card-foreground);
218
+ border-bottom: 2px solid var(--primary);
 
219
  padding-bottom: 0.5rem;
220
  display: inline-block;
221
  }
222
 
223
  .gr-button-primary {
224
+ background-color: var(--primary) !important;
225
  color: var(--primary-foreground) !important;
226
  border-radius: var(--radius) !important;
227
  font-weight: 600 !important;
228
+ transition: all 0.2s ease-in-out !important;
229
  padding: 0.75rem 1.5rem !important;
230
+ box-shadow: 0 4px 14px 0 rgba(0, 118, 255, 0.25) !important;
231
  width: 100%;
232
+ margin-top: 1rem;
 
233
  }
234
 
235
  .gr-button-primary:hover {
236
  transform: translateY(-2px) !important;
237
+ box-shadow: 0 6px 20px rgba(0, 118, 255, 0.35) !important;
238
  }
239
 
240
  .gr-form {
 
246
  border: 1px solid var(--border) !important;
247
  border-radius: var(--radius) !important;
248
  padding: 0.75rem 1rem !important;
249
+ transition: all 0.2s ease-in-out !important;
 
250
  }
251
 
252
  .gr-input:focus, .gr-select:focus {
253
  border-color: var(--primary) !important;
254
  box-shadow: 0 0 0 2px rgba(0, 118, 255, 0.25) !important;
 
255
  }
256
 
257
  .gr-panel {
 
262
  border: 1px solid var(--border) !important;
263
  border-radius: var(--radius) !important;
264
  overflow: hidden;
 
 
 
 
 
 
265
  }
266
 
267
  .footer {
268
+ margin-top: 2rem;
269
  border-top: 1px solid var(--border);
270
+ padding-top: 1.5rem;
271
+ font-size: 0.9rem;
272
  color: var(--card-foreground);
273
+ opacity: 0.7;
274
  text-align: center;
275
  }
276
 
277
  .footer-card {
278
  background-color: var(--card);
279
  border-radius: var(--radius);
280
+ padding: 1.5rem;
281
  box-shadow: var(--shadow);
 
 
 
 
 
 
282
  }
283
 
284
  .tips-grid {
285
  display: grid;
286
+ grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
287
+ gap: 1rem;
288
+ margin-top: 1rem;
289
  }
290
 
291
  .tip-card {
292
  background-color: var(--card);
293
  border-radius: var(--radius);
294
+ padding: 1rem;
295
+ border-left: 3px solid var(--primary);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  }
297
  """
298
 
 
512
  svg_header = f'<svg width="{img_width}" height="{img_height}" xmlns="http://www.w3.org/2000/svg">'
513
  svg_content = ""
514
 
515
+ # Color palette for different classes
516
  colors = [
517
+ "#FF3B30", "#FF9500", "#FFCC00", "#4CD964",
518
+ "#5AC8FA", "#007AFF", "#5856D6", "#FF2D55"
519
  ]
520
 
521
  for i, result in enumerate(json_results):
 
532
  # Select color based on class index
533
  color = colors[i % len(colors)]
534
 
535
+ # Create rectangle element
536
  svg_content += f'''
537
  <rect
538
  x="{x:.2f}"
 
540
  width="{width:.2f}"
541
  height="{height:.2f}"
542
  stroke="{color}"
543
+ stroke-width="2"
544
  fill="none"
 
 
545
  data-label="{label}"
546
  data-score="{score:.2f}"
547
  />
 
 
 
 
 
 
 
 
 
 
548
  <text
549
+ x="{x:.2f}"
550
+ y="{y-5:.2f}"
551
  font-family="Arial"
552
  font-size="12"
553
+ fill="{color}"
 
554
  >{label} ({score:.2f})</text>'''
555
 
556
  svg_footer = "\n</svg>"
 
561
  svg_header = f'<svg width="{img_width}" height="{img_height}" xmlns="http://www.w3.org/2000/svg">'
562
  svg_content = ""
563
 
564
+ # Color palette for different classes
565
  colors = [
566
+ "#FF3B30", "#FF9500", "#FFCC00", "#4CD964",
567
+ "#5AC8FA", "#007AFF", "#5856D6", "#FF2D55"
568
  ]
569
 
570
  for i, result in enumerate(json_results):
 
585
  <polygon
586
  points="{points_str}"
587
  stroke="{color}"
588
+ stroke-width="2"
589
  fill="{color}33"
590
  data-label="{label}"
591
  data-score="{score:.2f}"
 
605
  width="{width:.2f}"
606
  height="{height:.2f}"
607
  stroke="{color}"
608
+ stroke-width="1"
609
  fill="none"
 
 
610
  stroke-dasharray="5,5"
611
  />
 
 
 
 
 
 
 
 
 
 
612
  <text
613
+ x="{x:.2f}"
614
+ y="{y-5:.2f}"
615
  font-family="Arial"
616
  font-size="12"
617
+ fill="{color}"
 
618
  >{label} ({score:.2f})</text>'''
619
 
620
  svg_footer = "\n</svg>"
 
669
  with gr.Row(equal_height=True):
670
  with gr.Column(elem_classes="input-panel", scale=1):
671
  gr.Markdown("### Input")
672
+ input_image = gr.Image(label="Upload Image", type="numpy", height=300)
673
  text_prompt = gr.Textbox(
674
  label="Text Prompt",
675
+ placeholder="person, car, dog",
676
  value="person, car, dog",
677
  elem_classes="gr-input"
678
  )
 
690
  label="Model Size",
691
  elem_classes="gr-select"
692
  )
693
+ detect_button = gr.Button("Detect Objects", elem_classes="gr-button-primary")
694
 
695
  with gr.Column(elem_classes="output-panel", scale=1):
696
  gr.Markdown("### Results")
 
708
  with gr.Row(equal_height=True):
709
  with gr.Column(elem_classes="input-panel", scale=1):
710
  gr.Markdown("### Input")
711
+ seg_input_image = gr.Image(label="Upload Image", type="numpy", height=300)
712
  with gr.Row():
713
  seg_confidence = gr.Slider(
714
  minimum=0.1,
 
723
  label="Model Size",
724
  elem_classes="gr-select"
725
  )
726
+ segment_button = gr.Button("Segment Image", elem_classes="gr-button-primary")
727
 
728
  with gr.Column(elem_classes="output-panel", scale=1):
729
  gr.Markdown("### Results")
 
742
  gr.Markdown("### Tips & Information")
743
  with gr.Row(elem_classes="tips-grid"):
744
  with gr.Column(elem_classes="tip-card"):
745
+ gr.Markdown("**Detection**")
746
  gr.Markdown("Enter comma-separated text prompts to specify what objects to detect")
747
 
748
  with gr.Column(elem_classes="tip-card"):
749
+ gr.Markdown("**Segmentation**")
750
  gr.Markdown("The model will identify and segment common objects automatically")
751
 
752
  with gr.Column(elem_classes="tip-card"):
753
+ gr.Markdown("**Models**")
754
  gr.Markdown("Larger models provide better accuracy but require more processing power")
755
 
756
  with gr.Column(elem_classes="tip-card"):
757
+ gr.Markdown("**Output**")
758
  gr.Markdown("JSON output provides coordinates as percentages, compatible with SVG")
759
 
760
  # Set up event handlers