Spaces:
Sleeping
Sleeping
Upload app.ipynb with huggingface_hub
Browse files
app.ipynb
CHANGED
@@ -55,7 +55,7 @@
|
|
55 |
"metadata": {},
|
56 |
"outputs": [],
|
57 |
"source": [
|
58 |
-
"pn.extension(\"tabulator\"
|
59 |
"\n",
|
60 |
"template = pn.template.BootstrapTemplate(title=\"Ralstonia Annotation Tool\")"
|
61 |
]
|
@@ -107,24 +107,31 @@
|
|
107 |
]
|
108 |
},
|
109 |
{
|
110 |
-
"cell_type": "
|
|
|
111 |
"metadata": {},
|
|
|
112 |
"source": [
|
113 |
-
"
|
|
|
|
|
|
|
|
|
|
|
114 |
]
|
115 |
},
|
116 |
{
|
117 |
"cell_type": "markdown",
|
118 |
"metadata": {},
|
119 |
"source": [
|
120 |
-
"
|
121 |
]
|
122 |
},
|
123 |
{
|
124 |
"cell_type": "markdown",
|
125 |
"metadata": {},
|
126 |
"source": [
|
127 |
-
"
|
128 |
]
|
129 |
},
|
130 |
{
|
@@ -138,14 +145,56 @@
|
|
138 |
" filename=f\"{EXPERIMENT}_raw.csv\",\n",
|
139 |
" button_type=\"success\",\n",
|
140 |
" label=\"Download template annotation file\",\n",
|
141 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
]
|
143 |
},
|
144 |
{
|
145 |
"cell_type": "markdown",
|
146 |
"metadata": {},
|
147 |
"source": [
|
148 |
-
"
|
149 |
]
|
150 |
},
|
151 |
{
|
@@ -154,18 +203,8 @@
|
|
154 |
"metadata": {},
|
155 |
"outputs": [],
|
156 |
"source": [
|
157 |
-
"
|
158 |
-
"table = pn.widgets.Tabulator(\n",
|
159 |
-
" value=pd.DataFrame(),\n",
|
160 |
-
" pagination=\"local\",\n",
|
161 |
-
" page_size=20,\n",
|
162 |
-
" sizing_mode=\"stretch_width\",\n",
|
163 |
-
")\n",
|
164 |
"\n",
|
165 |
-
"ck_show_finished = pn.widgets.ToggleIcon(\n",
|
166 |
-
" icon=\"eye-x\", size=\"4em\", active_icon=\"eye\", value=False\n",
|
167 |
-
")\n",
|
168 |
-
"mk_show_finished = pn.pane.Markdown(\"Hide complete plants\")\n",
|
169 |
"\n",
|
170 |
"@pn.depends(file_input.param.value, watch=True)\n",
|
171 |
"def on_file_loaded(value):\n",
|
@@ -176,88 +215,29 @@
|
|
176 |
" ret = pd.read_csv(string_io, sep=\";\").assign(\n",
|
177 |
" file_name=lambda x: x.filepath.str.replace(\".tif\", \".jpg\")\n",
|
178 |
" )\n",
|
179 |
-
" ret = ret[ret.treatment == \"RS\"]\n",
|
180 |
" if \"di\" not in ret:\n",
|
181 |
" ret[\"di\"] = 0\n",
|
182 |
" if \"done\" not in ret:\n",
|
183 |
" ret[\"done\"] = False\n",
|
184 |
"\n",
|
185 |
-
" table.value = ret"
|
186 |
-
|
187 |
-
},
|
188 |
-
{
|
189 |
-
"cell_type": "markdown",
|
190 |
-
"metadata": {},
|
191 |
-
"source": [
|
192 |
-
"### Annotation Tools"
|
193 |
-
]
|
194 |
-
},
|
195 |
-
{
|
196 |
-
"cell_type": "markdown",
|
197 |
-
"metadata": {},
|
198 |
-
"source": [
|
199 |
-
"#### Plant Selection"
|
200 |
-
]
|
201 |
-
},
|
202 |
-
{
|
203 |
-
"cell_type": "code",
|
204 |
-
"execution_count": null,
|
205 |
-
"metadata": {},
|
206 |
-
"outputs": [],
|
207 |
-
"source": [
|
208 |
-
"sl_plant = pn.widgets.Select(name=\"Plant\", options=[])\n",
|
209 |
"\n",
|
210 |
-
"@pn.depends(
|
211 |
-
"
|
|
|
|
|
|
|
|
|
|
|
212 |
" df = table.value\n",
|
213 |
-
" if \"done\" in df:\n",
|
|
|
214 |
" sl_plant.options = list(\n",
|
215 |
-
" df.plant.unique()
|
|
|
|
|
216 |
" )\n",
|
217 |
-
" mk_show_finished.object = (\n",
|
218 |
-
" \"Show complete plants\" if show_done is True else \"Hide complete plants\"\n",
|
219 |
-
" )"
|
220 |
-
]
|
221 |
-
},
|
222 |
-
{
|
223 |
-
"cell_type": "markdown",
|
224 |
-
"metadata": {},
|
225 |
-
"source": [
|
226 |
-
"#### Main Annotation UI"
|
227 |
-
]
|
228 |
-
},
|
229 |
-
{
|
230 |
-
"cell_type": "code",
|
231 |
-
"execution_count": null,
|
232 |
-
"metadata": {},
|
233 |
-
"outputs": [],
|
234 |
-
"source": [
|
235 |
-
"im_current = pn.pane.Image(max_width=800, max_height=800, sizing_mode=\"stretch_width\")\n",
|
236 |
-
"discrete_player = pn.widgets.DiscretePlayer(\n",
|
237 |
-
" name=\"Discrete Player\", options=[0], value=0, loop_policy=\"loop\"\n",
|
238 |
-
")\n",
|
239 |
-
"discrete_player.interval = 1000\n",
|
240 |
-
"ii_disease_index = pn.widgets.IntInput(\n",
|
241 |
-
" name=\"Disease Index\",\n",
|
242 |
-
" start=0,\n",
|
243 |
-
" end=4,\n",
|
244 |
-
" step=1,\n",
|
245 |
-
" value=0,\n",
|
246 |
-
" max_width=80,\n",
|
247 |
-
" sizing_mode=\"stretch_width\",\n",
|
248 |
-
")\n",
|
249 |
-
"\n",
|
250 |
-
"dwn_annotations = pn.widgets.FileDownload(\n",
|
251 |
-
" file=pt_data.joinpath(f\"{EXPERIMENT}_raw.csv\"),\n",
|
252 |
-
" filename=f\"{EXPERIMENT}_raw.csv\",\n",
|
253 |
-
" label=\" \",\n",
|
254 |
-
" name=\"Download Annotations\",\n",
|
255 |
-
" sizing_mode=\"stretch_width\",\n",
|
256 |
-
" icon=\"file-download\",\n",
|
257 |
-
" button_type=\"primary\",\n",
|
258 |
-
")\n",
|
259 |
-
"\n",
|
260 |
-
"updating: bool = False\n",
|
261 |
"\n",
|
262 |
"\n",
|
263 |
"@pn.cache(max_items=10, policy=\"LRU\")\n",
|
@@ -328,9 +308,11 @@
|
|
328 |
" table.value.to_csv(s_buf, sep=\";\")\n",
|
329 |
" s_buf.seek(0)\n",
|
330 |
" dwn_annotations.filename = f\"{EXPERIMENT}_{dt.now().strftime('%Y%d%m_%H%M%S')}.csv\"\n",
|
331 |
-
" dwn_annotations.label = \"Download\"\n",
|
332 |
" dwn_annotations.file = s_buf\n",
|
333 |
-
" dwn_annotations.
|
|
|
|
|
|
|
334 |
]
|
335 |
},
|
336 |
{
|
@@ -347,23 +329,41 @@
|
|
347 |
"outputs": [],
|
348 |
"source": [
|
349 |
"sidebar = pn.Column(\n",
|
350 |
-
" pn.Card(
|
351 |
-
"
|
352 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
353 |
" ck_show_finished,\n",
|
354 |
-
"
|
355 |
-
"
|
|
|
|
|
356 |
" ),\n",
|
357 |
")\n",
|
358 |
"main = pn.Column(\n",
|
359 |
" im_current,\n",
|
360 |
-
" pn.Row(
|
361 |
-
" # pn.layout.HSpacer(),\n",
|
362 |
-
" discrete_player,\n",
|
363 |
-
" ii_disease_index,\n",
|
364 |
-
" dwn_annotations,\n",
|
365 |
-
" # pn.layout.HSpacer(),\n",
|
366 |
-
" ),\n",
|
367 |
" max_width=800,\n",
|
368 |
" max_height=800,\n",
|
369 |
" sizing_mode=\"stretch_width\",\n",
|
|
|
55 |
"metadata": {},
|
56 |
"outputs": [],
|
57 |
"source": [
|
58 |
+
"pn.extension(\"tabulator\")\n",
|
59 |
"\n",
|
60 |
"template = pn.template.BootstrapTemplate(title=\"Ralstonia Annotation Tool\")"
|
61 |
]
|
|
|
107 |
]
|
108 |
},
|
109 |
{
|
110 |
+
"cell_type": "code",
|
111 |
+
"execution_count": null,
|
112 |
"metadata": {},
|
113 |
+
"outputs": [],
|
114 |
"source": [
|
115 |
+
"treatments = {\n",
|
116 |
+
" \"Ralstonia\": \"RS\",\n",
|
117 |
+
" \"Control\": \"CT\",\n",
|
118 |
+
" \"Hydric Stress\": \"HS\",\n",
|
119 |
+
" \"DC3000\": \"DC\",\n",
|
120 |
+
"}"
|
121 |
]
|
122 |
},
|
123 |
{
|
124 |
"cell_type": "markdown",
|
125 |
"metadata": {},
|
126 |
"source": [
|
127 |
+
"## User Interface"
|
128 |
]
|
129 |
},
|
130 |
{
|
131 |
"cell_type": "markdown",
|
132 |
"metadata": {},
|
133 |
"source": [
|
134 |
+
"### Widgets"
|
135 |
]
|
136 |
},
|
137 |
{
|
|
|
145 |
" filename=f\"{EXPERIMENT}_raw.csv\",\n",
|
146 |
" button_type=\"success\",\n",
|
147 |
" label=\"Download template annotation file\",\n",
|
148 |
+
" sizing_mode=\"stretch_width\",\n",
|
149 |
+
")\n",
|
150 |
+
"\n",
|
151 |
+
"file_input = pn.widgets.FileInput(accept=\".csv,.json\", sizing_mode=\"stretch_width\")\n",
|
152 |
+
"table = pn.widgets.Tabulator(\n",
|
153 |
+
" value=pd.DataFrame(),\n",
|
154 |
+
" pagination=\"local\",\n",
|
155 |
+
" page_size=20,\n",
|
156 |
+
" sizing_mode=\"stretch_width\",\n",
|
157 |
+
")\n",
|
158 |
+
"\n",
|
159 |
+
"\n",
|
160 |
+
"sl_treatment = pn.widgets.Select(\n",
|
161 |
+
" name=\"Treatment\", options=list(treatments.keys()), value=\"Ralstonia\"\n",
|
162 |
+
")\n",
|
163 |
+
"sl_plant = pn.widgets.Select(name=\"Plant\", options=[])\n",
|
164 |
+
"ck_show_finished = pn.widgets.Checkbox(name=\"Show completed plants\", value=False)\n",
|
165 |
+
"\n",
|
166 |
+
"im_current = pn.pane.Image(max_width=800, max_height=800, sizing_mode=\"stretch_width\")\n",
|
167 |
+
"discrete_player = pn.widgets.DiscretePlayer(\n",
|
168 |
+
" name=\"Discrete Player\", options=[0], value=0, loop_policy=\"loop\"\n",
|
169 |
+
")\n",
|
170 |
+
"discrete_player.interval = 500\n",
|
171 |
+
"ii_disease_index = pn.widgets.IntInput(\n",
|
172 |
+
" name=\"Disease Index\",\n",
|
173 |
+
" start=0,\n",
|
174 |
+
" end=4,\n",
|
175 |
+
" step=1,\n",
|
176 |
+
" value=0,\n",
|
177 |
+
" max_width=80,\n",
|
178 |
+
" sizing_mode=\"stretch_width\",\n",
|
179 |
+
")\n",
|
180 |
+
"\n",
|
181 |
+
"dwn_annotations = pn.widgets.FileDownload(\n",
|
182 |
+
" file=pt_data.joinpath(f\"{EXPERIMENT}_raw.csv\"),\n",
|
183 |
+
" filename=f\"{EXPERIMENT}_raw.csv\",\n",
|
184 |
+
" label=\"Download\",\n",
|
185 |
+
" name=\"Download Annotations\",\n",
|
186 |
+
" sizing_mode=\"stretch_width\",\n",
|
187 |
+
" icon=\"file-download\",\n",
|
188 |
+
" button_type=\"primary\",\n",
|
189 |
+
")\n",
|
190 |
+
"pg_completion = pn.indicators.Progress(name=\"Annotation progress\", value=0)"
|
191 |
]
|
192 |
},
|
193 |
{
|
194 |
"cell_type": "markdown",
|
195 |
"metadata": {},
|
196 |
"source": [
|
197 |
+
"### Callbacks"
|
198 |
]
|
199 |
},
|
200 |
{
|
|
|
203 |
"metadata": {},
|
204 |
"outputs": [],
|
205 |
"source": [
|
206 |
+
"updating: bool = False\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
"\n",
|
|
|
|
|
|
|
|
|
208 |
"\n",
|
209 |
"@pn.depends(file_input.param.value, watch=True)\n",
|
210 |
"def on_file_loaded(value):\n",
|
|
|
215 |
" ret = pd.read_csv(string_io, sep=\";\").assign(\n",
|
216 |
" file_name=lambda x: x.filepath.str.replace(\".tif\", \".jpg\")\n",
|
217 |
" )\n",
|
|
|
218 |
" if \"di\" not in ret:\n",
|
219 |
" ret[\"di\"] = 0\n",
|
220 |
" if \"done\" not in ret:\n",
|
221 |
" ret[\"done\"] = False\n",
|
222 |
"\n",
|
223 |
+
" table.value = ret\n",
|
224 |
+
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
"\n",
|
226 |
+
"@pn.depends(\n",
|
227 |
+
" table.param.value,\n",
|
228 |
+
" ck_show_finished.param.value,\n",
|
229 |
+
" sl_treatment.param.value,\n",
|
230 |
+
" watch=True,\n",
|
231 |
+
")\n",
|
232 |
+
"def on_table_changed(file: str, show_done: bool, treatment):\n",
|
233 |
" df = table.value\n",
|
234 |
+
" if \"done\" in df and \"treatment\" in df:\n",
|
235 |
+
" df = df[df.treatment == treatments[treatment]]\n",
|
236 |
" sl_plant.options = list(\n",
|
237 |
+
" df.plant.unique()\n",
|
238 |
+
" if show_done is True\n",
|
239 |
+
" else df[df.done == False].plant.unique()\n",
|
240 |
" )\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
"\n",
|
242 |
"\n",
|
243 |
"@pn.cache(max_items=10, policy=\"LRU\")\n",
|
|
|
308 |
" table.value.to_csv(s_buf, sep=\";\")\n",
|
309 |
" s_buf.seek(0)\n",
|
310 |
" dwn_annotations.filename = f\"{EXPERIMENT}_{dt.now().strftime('%Y%d%m_%H%M%S')}.csv\"\n",
|
|
|
311 |
" dwn_annotations.file = s_buf\n",
|
312 |
+
" dwn_annotations.visible = True\n",
|
313 |
+
"\n",
|
314 |
+
" pg_completion.max = len(table.value.plant.unique())\n",
|
315 |
+
" pg_completion.value = len(table.value[table.value.done == True].plant.unique())"
|
316 |
]
|
317 |
},
|
318 |
{
|
|
|
329 |
"outputs": [],
|
330 |
"source": [
|
331 |
"sidebar = pn.Column(\n",
|
332 |
+
" pn.Card(\n",
|
333 |
+
" pn.Column(\n",
|
334 |
+
" pn.pane.Markdown(\"**Step 1:** Doawload the annaotation template file.\"),\n",
|
335 |
+
" pn.pane.Alert(\n",
|
336 |
+
" \"\"\"Only download the template the first time, changes are stored on your computer only.\"\"\",\n",
|
337 |
+
" alert_type=\"danger\",\n",
|
338 |
+
" ),\n",
|
339 |
+
" dwn_template,\n",
|
340 |
+
" pn.pane.Markdown(\"**Step 2:** Uplaod the downloaded template file.\"),\n",
|
341 |
+
" file_input,\n",
|
342 |
+
" pn.pane.Markdown(\n",
|
343 |
+
" \"\"\"**Step 3:** Annotate images. \n",
|
344 |
+
" Uppon finishing or before closing the app us the download button next to the disease index selector to download the annotations.\"\"\"\n",
|
345 |
+
" ),\n",
|
346 |
+
" pn.pane.Alert(\n",
|
347 |
+
" \"If you want to resume an existing annotation session, upload your latest download.\",\n",
|
348 |
+
" alert_type=\"info\",\n",
|
349 |
+
" ),\n",
|
350 |
+
" ),\n",
|
351 |
+
" title=\"File Manager\",\n",
|
352 |
+
" ),\n",
|
353 |
+
" pn.WidgetBox(\n",
|
354 |
+
" \"#### Plant selection\",\n",
|
355 |
+
" sl_treatment,\n",
|
356 |
+
" sl_plant,\n",
|
357 |
" ck_show_finished,\n",
|
358 |
+
" sizing_mode=\"stretch_width\",\n",
|
359 |
+
" ),\n",
|
360 |
+
" pn.WidgetBox(\n",
|
361 |
+
" \"#### Annotation progress\", pg_completion, sizing_mode=\"stretch_width\"\n",
|
362 |
" ),\n",
|
363 |
")\n",
|
364 |
"main = pn.Column(\n",
|
365 |
" im_current,\n",
|
366 |
+
" pn.Row(discrete_player, ii_disease_index, dwn_annotations),\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
" max_width=800,\n",
|
368 |
" max_height=800,\n",
|
369 |
" sizing_mode=\"stretch_width\",\n",
|