Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -328,110 +328,116 @@ if __name__ == "__main__":
|
|
| 328 |
<p style='margin: 10px 0 0 0; font-size: 1.2em; opacity: 0.9;'>Compact interface for advanced document structure detection</p>
|
| 329 |
</div>
|
| 330 |
""")
|
|
|
|
|
|
|
|
|
|
| 331 |
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
)
|
| 342 |
-
|
| 343 |
-
# Divider
|
| 344 |
-
gr.HTML("<div class='section-divider'></div>")
|
| 345 |
-
|
| 346 |
-
# 2. Model Selection (Second)
|
| 347 |
-
gr.HTML("<h3>π€ Model Selection</h3>")
|
| 348 |
-
model_dropdown = gr.Dropdown(
|
| 349 |
-
choices=list(MODELS.keys()),
|
| 350 |
-
value="Egret XLarge",
|
| 351 |
-
label="AI Model",
|
| 352 |
-
info="Model will load automatically when analyzing",
|
| 353 |
-
interactive=True
|
| 354 |
-
)
|
| 355 |
-
|
| 356 |
-
# Divider
|
| 357 |
-
gr.HTML("<div class='section-divider'></div>")
|
| 358 |
-
|
| 359 |
-
# 3. Detection Parameters (Third)
|
| 360 |
-
gr.HTML("<h3>βοΈ Detection Settings</h3>")
|
| 361 |
-
|
| 362 |
-
with gr.Row():
|
| 363 |
-
conf_threshold = gr.Slider(
|
| 364 |
-
minimum=0.0,
|
| 365 |
-
maximum=1.0,
|
| 366 |
-
value=0.6,
|
| 367 |
-
step=0.05,
|
| 368 |
-
label="Confidence Threshold",
|
| 369 |
-
info="Minimum confidence for detections"
|
| 370 |
)
|
| 371 |
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
)
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
)
|
| 388 |
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
|
|
|
|
|
|
| 396 |
)
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
label="Show Class Labels and Confidence Scores",
|
| 401 |
-
info="Display detection labels on the output image",
|
| 402 |
-
interactive=True
|
| 403 |
-
)
|
| 404 |
-
|
| 405 |
-
# Divider
|
| 406 |
-
gr.HTML("<div class='section-divider'></div>")
|
| 407 |
-
|
| 408 |
-
# 4. Analyze Button (Last)
|
| 409 |
-
detect_btn = gr.Button(
|
| 410 |
-
"π Analyze Document",
|
| 411 |
-
variant="primary",
|
| 412 |
-
size="lg",
|
| 413 |
-
elem_classes=["analyze-btn"]
|
| 414 |
-
)
|
| 415 |
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
|
| 427 |
-
detection_info = gr.Textbox(
|
| 428 |
-
label="Detection Summary",
|
| 429 |
-
value="Ready for analysis. Upload an image and click 'Analyze Document'.",
|
| 430 |
-
interactive=False,
|
| 431 |
-
lines=2,
|
| 432 |
-
show_copy_button=True
|
| 433 |
-
)
|
| 434 |
-
|
| 435 |
# Event Handler
|
| 436 |
detect_btn.click(
|
| 437 |
fn=process_image,
|
|
|
|
| 328 |
<p style='margin: 10px 0 0 0; font-size: 1.2em; opacity: 0.9;'>Compact interface for advanced document structure detection</p>
|
| 329 |
</div>
|
| 330 |
""")
|
| 331 |
+
|
| 332 |
+
# LEFT COLUMN - Controls and Input
|
| 333 |
+
with gr.Column(scale=1):
|
| 334 |
|
| 335 |
+
# Controls Section
|
| 336 |
+
with gr.Group(elem_classes=["controls-container"]):
|
| 337 |
+
# 1. Image Upload (First)
|
| 338 |
+
gr.HTML("<h3 style='margin-top: 0;'>π Upload Document</h3>")
|
| 339 |
+
input_img = gr.Image(
|
| 340 |
+
label="Document Image",
|
| 341 |
+
type="pil",
|
| 342 |
+
height=300,
|
| 343 |
+
interactive=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
)
|
| 345 |
|
| 346 |
+
# Divider
|
| 347 |
+
gr.HTML("<div class='section-divider'></div>")
|
| 348 |
+
|
| 349 |
+
# 2. Model Selection (Second)
|
| 350 |
+
gr.HTML("<h3>π€ Model Selection</h3>")
|
| 351 |
+
model_dropdown = gr.Dropdown(
|
| 352 |
+
choices=list(MODELS.keys()),
|
| 353 |
+
value="Egret XLarge",
|
| 354 |
+
label="AI Model",
|
| 355 |
+
info="Model will load automatically when analyzing",
|
| 356 |
+
interactive=True
|
| 357 |
)
|
| 358 |
+
|
| 359 |
+
# Divider
|
| 360 |
+
gr.HTML("<div class='section-divider'></div>")
|
| 361 |
+
|
| 362 |
+
# 3. Detection Parameters (Third)
|
| 363 |
+
gr.HTML("<h3>βοΈ Detection Settings</h3>")
|
| 364 |
+
|
| 365 |
+
with gr.Row():
|
| 366 |
+
conf_threshold = gr.Slider(
|
| 367 |
+
minimum=0.0,
|
| 368 |
+
maximum=1.0,
|
| 369 |
+
value=0.6,
|
| 370 |
+
step=0.05,
|
| 371 |
+
label="Confidence Threshold",
|
| 372 |
+
info="Minimum confidence for detections"
|
| 373 |
+
)
|
| 374 |
+
|
| 375 |
+
iou_threshold = gr.Slider(
|
| 376 |
+
minimum=0.0,
|
| 377 |
+
maximum=1.0,
|
| 378 |
+
value=0.5,
|
| 379 |
+
step=0.05,
|
| 380 |
+
label="NMS IoU Threshold",
|
| 381 |
+
info="Non-maximum suppression threshold"
|
| 382 |
+
)
|
| 383 |
+
|
| 384 |
+
with gr.Row():
|
| 385 |
+
nms_method = gr.Radio(
|
| 386 |
+
choices=["Custom IoMin", "Standard IoU"],
|
| 387 |
+
value="Custom IoMin",
|
| 388 |
+
label="NMS Algorithm",
|
| 389 |
+
info="Choose suppression method"
|
| 390 |
+
)
|
| 391 |
+
|
| 392 |
+
alpha_slider = gr.Slider(
|
| 393 |
+
minimum=0.0,
|
| 394 |
+
maximum=1.0,
|
| 395 |
+
value=0.3,
|
| 396 |
+
step=0.1,
|
| 397 |
+
label="Overlay Transparency",
|
| 398 |
+
info="Transparency of detection overlays"
|
| 399 |
+
)
|
| 400 |
+
|
| 401 |
+
show_labels_checkbox = gr.Checkbox(
|
| 402 |
+
value=True,
|
| 403 |
+
label="Show Class Labels and Confidence Scores",
|
| 404 |
+
info="Display detection labels on the output image",
|
| 405 |
+
interactive=True
|
| 406 |
)
|
| 407 |
|
| 408 |
+
# Divider
|
| 409 |
+
gr.HTML("<div class='section-divider'></div>")
|
| 410 |
+
|
| 411 |
+
# 4. Analyze Button (Last)
|
| 412 |
+
detect_btn = gr.Button(
|
| 413 |
+
"π Analyze Document",
|
| 414 |
+
variant="primary",
|
| 415 |
+
size="lg",
|
| 416 |
+
elem_classes=["analyze-btn"]
|
| 417 |
)
|
| 418 |
+
|
| 419 |
+
# RIGHT COLUMN - Results and Output
|
| 420 |
+
with gr.Column(scale=1):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 421 |
|
| 422 |
+
# Results Section
|
| 423 |
+
with gr.Group(elem_classes=["results-container"]):
|
| 424 |
+
gr.HTML("<h3 style='margin-top: 0;'>π― Analysis Results</h3>")
|
| 425 |
+
|
| 426 |
+
output_img = gr.Image(
|
| 427 |
+
label="Analyzed Document",
|
| 428 |
+
type="numpy",
|
| 429 |
+
height=600,
|
| 430 |
+
interactive=False
|
| 431 |
+
)
|
| 432 |
+
|
| 433 |
+
detection_info = gr.Textbox(
|
| 434 |
+
label="Detection Summary",
|
| 435 |
+
value="Ready for analysis. Upload an image and click 'Analyze Document'.",
|
| 436 |
+
interactive=False,
|
| 437 |
+
lines=2,
|
| 438 |
+
show_copy_button=True
|
| 439 |
+
)
|
| 440 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 441 |
# Event Handler
|
| 442 |
detect_btn.click(
|
| 443 |
fn=process_image,
|