Matis Despujols
commited on
Update app.py
Browse files
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
|
| 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="
|
| 160 |
|
| 161 |
gr.Markdown("""
|
| 162 |
-
#
|
| 163 |
|
| 164 |
-
Upload a screenshot or UI mockup to automatically detect
|
| 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="
|
| 173 |
height=400
|
| 174 |
)
|
| 175 |
|
| 176 |
-
with gr.Accordion("
|
| 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("
|
| 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="
|
| 212 |
height=400
|
| 213 |
)
|
| 214 |
|
| 215 |
-
summary_output = gr.Markdown(label="
|
| 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)
|