osbm commited on
Commit
994b6ed
·
verified ·
1 Parent(s): 5dd28a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -1
app.py CHANGED
@@ -6,6 +6,7 @@ from PIL import Image
6
  import albumentations as A
7
  from albumentations.pytorch import ToTensorV2
8
  import numpy as np
 
9
 
10
 
11
  model = UNet(
@@ -38,7 +39,7 @@ def process_image(image):
38
  return mask_pred[0, 0, :, :].numpy()
39
 
40
 
41
- demo = gr.Interface(
42
  fn=process_image,
43
  title="Histapathology segmentation",
44
  inputs=[
@@ -64,7 +65,44 @@ demo = gr.Interface(
64
  # os.path.join(os.path.dirname(__file__), "images/logo.png"),
65
  # os.path.join(os.path.dirname(__file__), "images/tower.jpg"),
66
  # ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  )
69
 
 
 
 
70
  demo.launch()
 
 
6
  import albumentations as A
7
  from albumentations.pytorch import ToTensorV2
8
  import numpy as np
9
+ import shutil
10
 
11
 
12
  model = UNet(
 
39
  return mask_pred[0, 0, :, :].numpy()
40
 
41
 
42
+ interface_image = gr.Interface(
43
  fn=process_image,
44
  title="Histapathology segmentation",
45
  inputs=[
 
65
  # os.path.join(os.path.dirname(__file__), "images/logo.png"),
66
  # os.path.join(os.path.dirname(__file__), "images/tower.jpg"),
67
  # ],
68
+ )
69
+
70
+ def process_slide(slide_path):
71
+ if not slide_path.endswith("zip"):
72
+ slide = openslide.OpenSlide(os.path.join(path, image_path))
73
+ else: # mrxs slide files
74
+ shutil.unpack_archive(slide_path, "cache_mrxs")
75
+
76
+ files = os.listdir("cache_mrxs")
77
+ slide_name = [file for file in files if file.endswith("mrxs")][0]
78
+ slide = openslide.OpenSlide(os.path.join("cache_mrxs", slide_name))
79
+
80
+ slide.get_thumbnail((512, 512))
81
+
82
+
83
 
84
+ return slide
85
+
86
+
87
+ interface_slide = gr.Interface(
88
+ fn=process_slide,
89
+ inputs=[
90
+ gr.File(
91
+ label="Input slide file (input zip for `.mrxs` files)",
92
+ )
93
+ ],
94
+ outputs=[
95
+ gr.Image(
96
+ label="Model Prediction",
97
+ image_mode="RGB",
98
+ height=400,
99
+ width=400,
100
+ )
101
+ ],
102
  )
103
 
104
+
105
+ demo = gr.TabbedInterface([interface_image, interface_slide], ["Image-to-Mask", "Slide-to-Mask"])
106
+
107
  demo.launch()
108
+