Matis Despujols commited on
Commit
aa2b37d
Β·
verified Β·
1 Parent(s): 64d6aeb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -36
app.py CHANGED
@@ -27,7 +27,7 @@ CLASS_COLORS = {
27
  # Global model variable
28
  model = None
29
 
30
- def load_model(model_path: str = "model/full_29.pth"):
31
  """Load RF-DETR model"""
32
  global model
33
  if model is None:
@@ -156,24 +156,23 @@ def detect_ui_elements(
156
  return annotated_pil, summary_text
157
 
158
  # Gradio interface
159
- with gr.Blocks(title="RF-DETR UI Element Detector", theme=gr.themes.Soft()) as demo:
160
 
161
  gr.Markdown("""
162
- # 🎯 RF-DETR UI Element Detector
163
 
164
- Upload a screenshot or UI mockup to automatically detect interactive elements.
165
- This model identifies 8 types of UI components: buttons, fields, headings, iframes, images, labels, links, and text.
166
  """)
167
 
168
  with gr.Row():
169
  with gr.Column(scale=1):
170
  input_image = gr.Image(
171
  type="pil",
172
- label="πŸ“€ Upload Screenshot",
173
  height=400
174
  )
175
 
176
- with gr.Accordion("βš™οΈ Detection Settings", open=True):
177
  confidence_slider = gr.Slider(
178
  minimum=0.1,
179
  maximum=0.9,
@@ -191,38 +190,17 @@ with gr.Blocks(title="RF-DETR UI Element Detector", theme=gr.themes.Soft()) as d
191
  label="Box Line Thickness"
192
  )
193
 
194
- detect_button = gr.Button("πŸ” Detect Elements", variant="primary", size="lg")
195
-
196
- gr.Markdown("""
197
- ### πŸ“Š Detected Classes:
198
- - 🟒 **button** - Interactive buttons
199
- - πŸ”΅ **field** - Input fields
200
- - 🟣 **heading** - Headers and titles
201
- - 🟑 **iframe** - Embedded frames
202
- - 🟠 **image** - Images and icons
203
- - πŸ”· **label** - Text labels
204
- - πŸ”΄ **link** - Hyperlinks
205
- - βšͺ **text** - Plain text
206
- """)
207
 
208
  with gr.Column(scale=1):
209
  output_image = gr.Image(
210
  type="pil",
211
- label="🎨 Detected Elements",
212
  height=400
213
  )
214
 
215
- summary_output = gr.Markdown(label="πŸ“‹ Detection Summary")
216
 
217
- # Examples
218
- gr.Markdown("### πŸ’‘ Try with example images:")
219
- gr.Examples(
220
- examples=[
221
- # Add example image paths here if available
222
- ],
223
- inputs=input_image,
224
- label="Example Screenshots"
225
- )
226
 
227
  # Connect button
228
  detect_button.click(
@@ -231,11 +209,6 @@ with gr.Blocks(title="RF-DETR UI Element Detector", theme=gr.themes.Soft()) as d
231
  outputs=[output_image, summary_output]
232
  )
233
 
234
- gr.Markdown("""
235
- ---
236
- **Model:** RF-DETR Medium (Resolution: 1600px) | **Framework:** PyTorch
237
- """)
238
-
239
  # Launch
240
  if __name__ == "__main__":
241
  demo.queue().launch(share=False)
 
27
  # Global model variable
28
  model = None
29
 
30
+ def load_model(model_path: str = "model.pth"):
31
  """Load RF-DETR model"""
32
  global model
33
  if model is None:
 
156
  return annotated_pil, summary_text
157
 
158
  # Gradio interface
159
+ with gr.Blocks(title="CU-1 UI Element Detector", theme=gr.themes.Soft()) as demo:
160
 
161
  gr.Markdown("""
162
+ # CU-1 UI Element Detector
163
 
164
+ Upload a screenshot or UI mockup to automatically detect elements.
 
165
  """)
166
 
167
  with gr.Row():
168
  with gr.Column(scale=1):
169
  input_image = gr.Image(
170
  type="pil",
171
+ label="Upload Screenshot",
172
  height=400
173
  )
174
 
175
+ with gr.Accordion("Detection Settings", open=True):
176
  confidence_slider = gr.Slider(
177
  minimum=0.1,
178
  maximum=0.9,
 
190
  label="Box Line Thickness"
191
  )
192
 
193
+ detect_button = gr.Button("Detect Elements", variant="primary", size="lg")
 
 
 
 
 
 
 
 
 
 
 
 
194
 
195
  with gr.Column(scale=1):
196
  output_image = gr.Image(
197
  type="pil",
198
+ label="Detected Elements",
199
  height=400
200
  )
201
 
202
+ summary_output = gr.Markdown(label="Detection Summary")
203
 
 
 
 
 
 
 
 
 
 
204
 
205
  # Connect button
206
  detect_button.click(
 
209
  outputs=[output_image, summary_output]
210
  )
211
 
 
 
 
 
 
212
  # Launch
213
  if __name__ == "__main__":
214
  demo.queue().launch(share=False)