alrichardbollans commited on
Commit
a8b7713
·
1 Parent(s): efacbd3

Add tab navigation

Browse files
Files changed (1) hide show
  1. app.py +68 -54
app.py CHANGED
@@ -1,14 +1,3 @@
1
- # import detectron2
2
- # import torch
3
- #
4
- # # Check this in logs
5
- # try:
6
- # print(f"Is CUDA available: {torch.cuda.is_available()}")
7
- # # True
8
- # print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
9
- # except:
10
- # print('Couldnt find CUDA device')
11
-
12
  import base64
13
  import tempfile
14
  from pathlib import Path
@@ -28,8 +17,13 @@ from python_utils import load_model, apply_nms, OPTIMAL_NMS_THRESHOLD, MODEL_VER
28
  app_dir = Path(__file__).parent
29
 
30
  protocol_url = 'https://pgomba.github.io/orchid_protocol/'
31
- acknowledgement_text = "The OrchAId TZ viability dataset used to develop the model was created by the Royal Botanic Gardens, Kew, Silo National des Graines Forestieres, Madagascar, the Ministry of Agriculture, Lands, Housing and Environment, Monsterrat, Instituto de Investigação Agrária de Moçambique, Mozambique, Departmento de Recursos Naturales y Ambientales, Puerto Rico & the National Parks Trust of the Virgin Islands."
32
-
 
 
 
 
 
33
  # Load the prediction model
34
  predictor = load_model()
35
  main_app = ui.page_fluid(
@@ -41,7 +35,8 @@ main_app = ui.page_fluid(
41
  multiple=True,
42
  accept=[".png", ".jpg", ".jpeg"]),
43
 
44
- ui.input_slider("threshold", f"Threshold for Discarding Overlapping Segmentations (Default: {OPTIMAL_NMS_THRESHOLD})", 0, 1.0,
 
45
  OPTIMAL_NMS_THRESHOLD),
46
 
47
  ui.tags.style("""
@@ -115,51 +110,70 @@ app_ui = ui.page_fluid(
115
  ),
116
  class_="nav-bar"
117
  ),
118
-
119
- ui.div(
120
- ui.h4("Model Overview"),
121
- ui.p(
122
- "This app uses a computer vision model trained to analyse images of orchid tetrazolium chloride tests to count the number of viable, non-viable and empty seeds."
123
- " Full details of the model, training process and evaluation can be found on the project ",
124
- ui.a("GitHub repository", href=github_repo_url, target="_blank"),
125
- "."),
126
-
127
- ui.h5('Performance'),
128
- ui.p('To briefly summarise model performance on our test dataset, '),
129
- ui.p('Disclaimer: the evaluation of the model applies to our dataset and there are many factors that may influence performance of the model on new images.'
130
- ' We recommend visually inspecting at least a few images to ensure the model is performing as expected on your batch of images.'),
131
- ui.h4("Using this App"),
132
- ui.p(
133
- "This app is built for use with ", ui.HTML("<b>specific types of images</b>"),
134
- " -- the protocol for taking images compatible with this model is available on ",
135
- ui.a("GitHub", href=protocol_url, target="_blank"),
136
- ". The protocol is available in English, Indonesian, Thai, French, Spanish, Portuguese, Arabic, Mandarin, Malagasy and Japanese."),
137
- ui.p(
138
- "To use this app, upload images and click 'Analyse'."
139
- " Segmented images will be displayed in the right-hand panel, showing viable seeds in red, non-viable in yellow and empty in black. An opacity slider can be used to adjust the transparency of the segmentation masks."
140
- " The counts will also be displayed as text and results can be downloaded using the 'Download Results' button."),
141
-
142
- ui.p(
143
- f"Before analysing images it is possible to change the threshold used to discard overlapping segmentations produced by the model. The default threshold is {OPTIMAL_NMS_THRESHOLD} as this was found to be optimal for our data, but you can adjust this value in the slider."
144
- f" We recommend leaving this as the default, and only decreasing the value if you find that your images have many overlapping seeds and some of them are not being included in the output. Similarly, you can increase this value if your images have very few overlapping seeds and the output includes multiple segmentations of the same seed."),
145
- ui.p(" If you have any feedback on the app, please start a discussion on the project ",
146
- ui.a("HuggingFace space", href=discussion_url, target="_blank"), '.'
147
- ),
148
-
149
- class_="body-bar"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  ),
151
- main_app,
152
- # ui.page_navbar(
153
- # ui.nav_panel("A", main_app),
154
- # ui.nav_panel("C", "Page C content"),
155
- # title="App with navbar",
156
- # id="page",
157
- # ),
158
  ui.div(
159
  ui.h4("Acknowledgements"),
160
  ui.p(
161
  acknowledgement_text
162
- ),
 
 
 
163
  class_="acknowledgement-bar"
164
  ),
165
  ui.div(
 
 
 
 
 
 
 
 
 
 
 
 
1
  import base64
2
  import tempfile
3
  from pathlib import Path
 
17
  app_dir = Path(__file__).parent
18
 
19
  protocol_url = 'https://pgomba.github.io/orchid_protocol/'
20
+ acknowledgement_text = ("The OrchAId TZ viability dataset used to develop the model was created by the Royal Botanic Gardens, Kew, Silo National des "
21
+ "Graines Forestieres, Madagascar, the Ministry of Agriculture, Lands, Housing and Environment, Monsterrat, "
22
+ "Instituto de Investigação Agrária de Moçambique, Mozambique, Departmento de Recursos Naturales y Ambientales, "
23
+ "Puerto Rico & the National Parks Trust of the Virgin Islands.")
24
+ disclaimer_text = ('Disclaimer: the evaluation of the model applies to our dataset and there are many factors that may influence performance of the '
25
+ 'model on new images.'
26
+ ' We recommend visually inspecting at least a few images to ensure the model is performing as expected on your batch of images.')
27
  # Load the prediction model
28
  predictor = load_model()
29
  main_app = ui.page_fluid(
 
35
  multiple=True,
36
  accept=[".png", ".jpg", ".jpeg"]),
37
 
38
+ ui.input_slider("threshold", f"Threshold for Discarding Overlapping Segmentations (Default: {OPTIMAL_NMS_THRESHOLD})",
39
+ 0, 1.0,
40
  OPTIMAL_NMS_THRESHOLD),
41
 
42
  ui.tags.style("""
 
110
  ),
111
  class_="nav-bar"
112
  ),
113
+ ui.navset_tab(
114
+ ui.nav_panel('App', main_app
115
+ ),
116
+ ui.nav_panel('Instructions', ui.div(
117
+ ui.h4("Using this App"),
118
+ ui.p(
119
+ "This app uses a computer vision model trained to analyse images of orchid tetrazolium chloride tests to count the number of "
120
+ "viable, non-viable and empty orchid seeds. ",
121
+ disclaimer_text),
122
+ ui.p(
123
+ "The app is built for use with ", ui.HTML("<b>specific types of images</b>"),
124
+ " -- the protocol for taking images compatible with this model is available on ",
125
+ ui.a("GitHub", href=protocol_url, target="_blank"),
126
+ ". The protocol is available in English, Indonesian, Thai, French, Spanish, Portuguese, Arabic, Mandarin, Malagasy and Japanese."),
127
+ ui.p(
128
+ "To use this app, upload images and click 'Analyse'."
129
+ " Segmented images will be displayed in the right-hand panel, showing viable seeds in red, non-viable in yellow and empty in black."
130
+ " An opacity slider can be used to adjust the transparency of the segmentation masks."
131
+ " The counts will also be displayed as text and results can be downloaded using the 'Download Results' button, providing a data "
132
+ "table with the filename of each image and the counts of viable, non-viable and empty seeds."),
133
+
134
+ ui.p(
135
+ f"Before analysing images it is possible to change the threshold used to discard overlapping segmentations produced by the model. "
136
+ f"The default threshold is {OPTIMAL_NMS_THRESHOLD} as this was found to be optimal for our data, but you can adjust this value in "
137
+ f"the slider."
138
+ f" We recommend leaving this as the default, and only decreasing the value if you find that your images have many overlapping seeds "
139
+ f"and some of them are not being included in the output. Similarly, you can increase this value if your images have very few "
140
+ f"overlapping seeds and the output includes multiple segmentations of the same seed."),
141
+ ui.p(" If you have any feedback on the app, please start a discussion on the project ",
142
+ ui.a("HuggingFace Space", href=discussion_url, target="_blank"), '.'
143
+ ),
144
+
145
+ class_="body-bar"
146
+
147
+ )),
148
+ ui.nav_panel('Model Overview',
149
+ ui.div(
150
+ ui.p(
151
+ "We developed "
152
+
153
+ "You can find a project overview ", ui.a("here",
154
+ href='https://www.kew.org/science/our-science/projects/machine-learning-to-improve-orchid-viability-testing',
155
+ target="_blank"),'.'
156
+ " Full details of the model, training process and evaluation can be found on the project ",
157
+ ui.a("GitHub repository", href=github_repo_url, target="_blank"),
158
+ "."),
159
+
160
+ ui.h5('Data Summary'),
161
+ ui.p('Note that the upper limit for the number of detected seeds in a single image is 800.'),
162
+ ui.h5('Performance'),
163
+ ui.p('To briefly summarise model performance on our test dataset, '),
164
+ ui.p(disclaimer_text
165
+ ),
166
+ class_="body-bar"))
167
+ , id='tab'
168
  ),
 
 
 
 
 
 
 
169
  ui.div(
170
  ui.h4("Acknowledgements"),
171
  ui.p(
172
  acknowledgement_text
173
+ ), ui.p(
174
+ "The developers acknowledge Research Computing at the James Hutton Institute for providing computational resources and technical "
175
+ "support for the 'UK’s Crop Diversity Bioinformatics HPC' (BBSRC grants BB/S019669/1 and BB/X019683/1), use of which has contributed to "
176
+ "the development of the model used in this app."),
177
  class_="acknowledgement-bar"
178
  ),
179
  ui.div(