Spaces:
Running
Running
halleewong
commited on
Commit
•
a7dc41c
1
Parent(s):
8d1c21c
resize 1000x1000
Browse files- app.py +31 -12
- test_examples/ACDC.jpg +0 -0
- test_examples/BTCV.jpg +0 -0
- test_examples/BUID.jpg +0 -0
- test_examples/BUID_1000.jpg +0 -0
- test_examples/COBRE.jpg +0 -0
- test_examples/DRIVE.jpg +0 -0
- test_examples/DRIVE_28_training.png +0 -0
- test_examples/HipXRay.jpg +0 -0
- test_examples/HipXRay_image_054.png +0 -0
- test_examples/PanDental.jpg +0 -0
- test_examples/PanDental_1000.jpg +0 -0
- test_examples/SCD.jpg +0 -0
- test_examples/SCD_1000.jpg +0 -0
- test_examples/SpineWeb.jpg +0 -0
- test_examples/TotalSeg_s0010_1.png +0 -0
- test_examples/TotalSeg_s0028_1.png +0 -0
- test_examples/TotalSeg_s0045_1.png +0 -0
- test_examples/TotalSegmentator.jpg +0 -0
- test_examples/TotalSegmentator_2.jpg +0 -0
- test_examples/WBC.jpg +0 -0
- test_examples/WBC_1000.jpg +0 -0
- test_examples/patient023_frame01.png +0 -0
- test_examples/patient061_frame01.png +0 -0
app.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import torch
|
@@ -11,6 +13,7 @@ device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
|
11 |
|
12 |
from predictor import Predictor
|
13 |
|
|
|
14 |
H = 256
|
15 |
W = 256
|
16 |
|
@@ -96,7 +99,13 @@ def image_overlay(img, mask=None, scribbles=None, contour=False, alpha=0.5):
|
|
96 |
return output
|
97 |
|
98 |
|
99 |
-
def viz_pred_mask(img,
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
"""
|
101 |
Visualize image with clicks, scribbles, predicted mask overlaid
|
102 |
"""
|
@@ -266,7 +275,7 @@ def get_select_coords(predictor, input_img, brush_label, bbox_label, best_mask,
|
|
266 |
# Don't update output image if waiting for additional bounding box click
|
267 |
return click_input_viz, scribble_input_viz, output_img, best_mask, low_res_mask, img_features, click_coords, click_labels, bbox_coords, seperate_scribble_masks, last_scribble_mask
|
268 |
|
269 |
-
|
270 |
def undo_click(predictor, input_img, brush_label, bbox_label, best_mask, low_res_mask, click_coords, click_labels, bbox_coords,
|
271 |
seperate_scribble_masks, last_scribble_mask, scribble_img, img_features,
|
272 |
output_img, binary_checkbox, multimask_mode, autopredict_checkbox):
|
@@ -373,10 +382,9 @@ with gr.Blocks(theme=gr.themes.Default(text_size=gr.themes.sizes.text_lg)) as de
|
|
373 |
multimask_mode = gr.Checkbox(value=True, label="Multi-mask mode", visible=False)
|
374 |
|
375 |
with gr.Row():
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
red_brush = gr.Brush(colors=["#FF0000"], color_mode="fixed", default_size=2)
|
380 |
|
381 |
with gr.Column(scale=1):
|
382 |
with gr.Tab("Scribbles"):
|
@@ -388,8 +396,9 @@ with gr.Blocks(theme=gr.themes.Default(text_size=gr.themes.sizes.text_lg)) as de
|
|
388 |
value=default_example,
|
389 |
transforms=(),
|
390 |
sources=(),
|
|
|
391 |
show_download_button=True,
|
392 |
-
|
393 |
)
|
394 |
|
395 |
with gr.Tab("Clicks/Boxes") as click_tab:
|
@@ -398,9 +407,8 @@ with gr.Blocks(theme=gr.themes.Default(text_size=gr.themes.sizes.text_lg)) as de
|
|
398 |
type='numpy',
|
399 |
value=default_example,
|
400 |
show_download_button=True,
|
401 |
-
sources=(),
|
402 |
container=True,
|
403 |
-
|
404 |
)
|
405 |
with gr.Row():
|
406 |
undo_click_button = gr.Button("Undo Last Click")
|
@@ -411,8 +419,9 @@ with gr.Blocks(theme=gr.themes.Default(text_size=gr.themes.sizes.text_lg)) as de
|
|
411 |
label="Input",
|
412 |
image_mode="L",
|
413 |
value=default_example,
|
414 |
-
|
415 |
-
|
|
|
416 |
)
|
417 |
gr.Markdown("To upload your own image: click the `x` in the top right corner to clear the current image, then drag & drop")
|
418 |
|
@@ -424,7 +433,7 @@ with gr.Blocks(theme=gr.themes.Default(text_size=gr.themes.sizes.text_lg)) as de
|
|
424 |
elem_id="gallery",
|
425 |
preview=True,
|
426 |
object_fit="scale-down",
|
427 |
-
|
428 |
container=True
|
429 |
)
|
430 |
|
@@ -451,6 +460,16 @@ with gr.Blocks(theme=gr.themes.Default(text_size=gr.themes.sizes.text_lg)) as de
|
|
451 |
label='Examples from datasets unseen during training'
|
452 |
)
|
453 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
454 |
# When clear clicks button is clicked
|
455 |
def clear_click_history(input_img):
|
456 |
return input_img, input_img, [], [], [], None, None
|
|
|
1 |
+
from ast import Interactive
|
2 |
+
from xml.sax.xmlreader import InputSource
|
3 |
import gradio as gr
|
4 |
import numpy as np
|
5 |
import torch
|
|
|
13 |
|
14 |
from predictor import Predictor
|
15 |
|
16 |
+
display_height = 600
|
17 |
H = 256
|
18 |
W = 256
|
19 |
|
|
|
99 |
return output
|
100 |
|
101 |
|
102 |
+
def viz_pred_mask(img,
|
103 |
+
mask=None,
|
104 |
+
point_coords=None,
|
105 |
+
point_labels=None,
|
106 |
+
bbox_coords=None,
|
107 |
+
seperate_scribble_masks=None,
|
108 |
+
binary=True):
|
109 |
"""
|
110 |
Visualize image with clicks, scribbles, predicted mask overlaid
|
111 |
"""
|
|
|
275 |
# Don't update output image if waiting for additional bounding box click
|
276 |
return click_input_viz, scribble_input_viz, output_img, best_mask, low_res_mask, img_features, click_coords, click_labels, bbox_coords, seperate_scribble_masks, last_scribble_mask
|
277 |
|
278 |
+
|
279 |
def undo_click(predictor, input_img, brush_label, bbox_label, best_mask, low_res_mask, click_coords, click_labels, bbox_coords,
|
280 |
seperate_scribble_masks, last_scribble_mask, scribble_img, img_features,
|
281 |
output_img, binary_checkbox, multimask_mode, autopredict_checkbox):
|
|
|
382 |
multimask_mode = gr.Checkbox(value=True, label="Multi-mask mode", visible=False)
|
383 |
|
384 |
with gr.Row():
|
385 |
+
|
386 |
+
green_brush = gr.Brush(colors=["#00FF00"], color_mode="fixed", default_size=3)
|
387 |
+
red_brush = gr.Brush(colors=["#FF0000"], color_mode="fixed", default_size=3)
|
|
|
388 |
|
389 |
with gr.Column(scale=1):
|
390 |
with gr.Tab("Scribbles"):
|
|
|
396 |
value=default_example,
|
397 |
transforms=(),
|
398 |
sources=(),
|
399 |
+
container=True,
|
400 |
show_download_button=True,
|
401 |
+
height=display_height+60
|
402 |
)
|
403 |
|
404 |
with gr.Tab("Clicks/Boxes") as click_tab:
|
|
|
407 |
type='numpy',
|
408 |
value=default_example,
|
409 |
show_download_button=True,
|
|
|
410 |
container=True,
|
411 |
+
height=display_height
|
412 |
)
|
413 |
with gr.Row():
|
414 |
undo_click_button = gr.Button("Undo Last Click")
|
|
|
419 |
label="Input",
|
420 |
image_mode="L",
|
421 |
value=default_example,
|
422 |
+
show_download_button=True,
|
423 |
+
container=True,
|
424 |
+
height=display_height
|
425 |
)
|
426 |
gr.Markdown("To upload your own image: click the `x` in the top right corner to clear the current image, then drag & drop")
|
427 |
|
|
|
433 |
elem_id="gallery",
|
434 |
preview=True,
|
435 |
object_fit="scale-down",
|
436 |
+
height=display_height+60,
|
437 |
container=True
|
438 |
)
|
439 |
|
|
|
460 |
label='Examples from datasets unseen during training'
|
461 |
)
|
462 |
|
463 |
+
# with gr.Accordion():
|
464 |
+
# height_scribble = gr.Number(label="Scribble Panel Height",
|
465 |
+
# value=display_height, Interactive=True)
|
466 |
+
|
467 |
+
# height_scribble.change(
|
468 |
+
# fn=lambda x: gr.update(height=x),
|
469 |
+
# inputs=[scribble_img],
|
470 |
+
# outputs=[scribble_img],
|
471 |
+
# )
|
472 |
+
|
473 |
# When clear clicks button is clicked
|
474 |
def clear_click_history(input_img):
|
475 |
return input_img, input_img, [], [], [], None, None
|
test_examples/ACDC.jpg
DELETED
Binary file (13.8 kB)
|
|
test_examples/BTCV.jpg
DELETED
Binary file (17.2 kB)
|
|
test_examples/BUID.jpg
DELETED
Binary file (21.2 kB)
|
|
test_examples/BUID_1000.jpg
ADDED
test_examples/COBRE.jpg
DELETED
Binary file (15.3 kB)
|
|
test_examples/DRIVE.jpg
DELETED
Binary file (16.4 kB)
|
|
test_examples/DRIVE_28_training.png
ADDED
test_examples/HipXRay.jpg
DELETED
Binary file (15 kB)
|
|
test_examples/HipXRay_image_054.png
ADDED
test_examples/PanDental.jpg
DELETED
Binary file (11.9 kB)
|
|
test_examples/PanDental_1000.jpg
ADDED
test_examples/SCD.jpg
DELETED
Binary file (21.8 kB)
|
|
test_examples/SCD_1000.jpg
ADDED
test_examples/SpineWeb.jpg
DELETED
Binary file (17.9 kB)
|
|
test_examples/TotalSeg_s0010_1.png
ADDED
test_examples/TotalSeg_s0028_1.png
ADDED
test_examples/TotalSeg_s0045_1.png
ADDED
test_examples/TotalSegmentator.jpg
DELETED
Binary file (14 kB)
|
|
test_examples/TotalSegmentator_2.jpg
DELETED
Binary file (16.1 kB)
|
|
test_examples/WBC.jpg
DELETED
Binary file (19.2 kB)
|
|
test_examples/WBC_1000.jpg
ADDED
test_examples/patient023_frame01.png
ADDED
test_examples/patient061_frame01.png
ADDED