caviri
commited on
Commit
·
a56673f
1
Parent(s):
6014cc3
ci: Test HF
Browse files- app/main.py +306 -312
app/main.py
CHANGED
@@ -1,342 +1,336 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
|
21 |
# with gr.Blocks(theme=theme, css=css) as demo:
|
22 |
-
|
23 |
-
#
|
24 |
-
#
|
25 |
-
#
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
# object_fit="contain", height="auto", interactive=False)
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
|
310 |
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
|
319 |
-
|
320 |
-
|
321 |
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
|
328 |
-
#
|
329 |
-
#
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
#
|
334 |
|
335 |
-
def greet(name):
|
336 |
-
return f"Hello, {name}!"
|
337 |
|
338 |
-
demo2 = gr.Interface(fn=greet, inputs="text", outputs="text")
|
339 |
-
|
340 |
if __name__ == "__main__":
|
341 |
-
|
342 |
-
#demo.launch(server_name="0.0.0.0", server_port=3333)
|
|
|
1 |
import gradio as gr
|
2 |
+
from gradio_modal import Modal
|
3 |
|
4 |
+
from validation_submission.create_json import create_json_all_individuals, create_json_one_individual, create_tmp, reset_json
|
5 |
+
from validation_submission.add_json import add_data_to_individual
|
6 |
+
from validation_submission.validation import reset_error_box
|
7 |
+
from display import save_display_individual
|
8 |
+
from geolocalisation.maps import get_location
|
9 |
+
from functools import partial
|
10 |
+
from dead import show_section_dead
|
11 |
+
from wounded import show_section_wounded
|
12 |
+
from circumstances.circumstances import show_circumstances
|
13 |
+
from circumstances.circumstances_dropdowns import *
|
14 |
+
from physical.physical_select_animal import show_physical, find_bounding_box
|
15 |
+
from physical.physical_checkbox import on_select_body_part, hide_physical
|
16 |
+
from behavior.behavior_checkbox import show_behavior, on_select_behavior
|
17 |
+
from follow_up.followup_events import save_fe
|
18 |
+
from styling.style import *
|
19 |
+
from styling.theme import css
|
20 |
|
21 |
# with gr.Blocks(theme=theme, css=css) as demo:
|
22 |
+
with gr.Blocks(theme='shivi/calm_seafoam') as demo:
|
23 |
+
#create_json_all_individuals()
|
24 |
+
# ---------------------------------------------------------
|
25 |
+
# Intro Text
|
26 |
+
with gr.Row():
|
27 |
+
with gr.Column(scale=1):
|
28 |
+
title = gr.Markdown("# Welcome to Digiwild", label="Title")
|
29 |
+
description = gr.Markdown("Please record your wildlife observations here !", label="description")
|
30 |
+
with gr.Row():
|
31 |
+
show_modal = gr.Button("Add an Animal", scale=3)
|
32 |
+
submit_button = gr.Button("Submit All Animals", scale=1)
|
33 |
+
df = gr.Dataframe(headers=["Identifier", "Location", "Wounded", "Dead"], visible=False, interactive=False)
|
34 |
+
gallery = gr.Gallery(
|
35 |
+
label="Gallery of Records", elem_id="gallery",
|
36 |
+
columns=[1], rows=[1],
|
37 |
+
object_fit="contain", height="auto", interactive=False)
|
|
|
38 |
|
39 |
+
with Modal(visible=False) as modal:
|
40 |
+
# ---------------------------------------------------------
|
41 |
+
# Intro Text
|
42 |
+
with gr.Row():
|
43 |
+
with gr.Column(scale=1):
|
44 |
+
title = gr.Markdown("# Animal Report", label="Title")
|
45 |
+
description = gr.Markdown("Please record your observation here.", label="description")
|
46 |
|
47 |
+
# ---------------------------------------------------------
|
48 |
+
# Camera
|
49 |
+
with gr.Row():
|
50 |
+
def save_image(camera):
|
51 |
+
add_data_to_individual("image", camera.tolist())
|
52 |
|
53 |
+
camera = gr.Image(elem_id="image")
|
54 |
+
camera.input(save_image, inputs=[camera])
|
55 |
+
# ---------------------------------------------------------
|
56 |
+
# Location
|
57 |
+
#with gr.Row():
|
58 |
+
with gr.Column(scale=1):
|
59 |
+
location = gr.Textbox(visible=True, interactive=True, label="Location of Sighting")
|
60 |
+
#display location processing
|
61 |
+
identified_location= gr.Textbox(visible=False, interactive=False,
|
62 |
+
label="Identified GPS Location")
|
63 |
+
with gr.Row():
|
64 |
+
#to submit it
|
65 |
+
submit_location = gr.Button("Get GPS Coordinates",
|
66 |
+
visible=True, interactive=True, scale=3)
|
67 |
+
submit_location.click(get_location, inputs=[location], outputs=[identified_location])
|
68 |
+
#to clear it
|
69 |
+
clear_location = gr.ClearButton(components=[location, identified_location],
|
70 |
+
visible=True, interactive=True, scale=1
|
71 |
+
)
|
72 |
+
clear_location.click()
|
73 |
|
74 |
+
# ---------------------------------------------------------
|
75 |
+
# ---------------------------------------------------------
|
76 |
+
# Dead and Wounded Buttons
|
77 |
+
gr.Markdown("## The State of the Animal", label="Title")
|
78 |
+
gr.Markdown("Please tell us if the animal was wounded or dead.", label="description")
|
79 |
+
with gr.Row() as block_form:
|
80 |
+
with gr.Column(scale=1):
|
81 |
+
butt_wounded = gr.Button("Wounded", elem_id="wounded")
|
82 |
+
with gr.Column(scale=1):
|
83 |
+
butt_dead = gr.Button("Dead", elem_id="dead")
|
84 |
|
85 |
+
# ---------------------------------------------------------
|
86 |
+
# Initiate sections
|
87 |
+
section_dead, radio_circumstance_dead, radio_physical_dead,\
|
88 |
+
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
|
89 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
|
90 |
+
physical_boxes_dead, \
|
91 |
+
checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead, \
|
92 |
+
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
|
93 |
+
fe_name_recipient_dead, fe_collection_ref_dead \
|
94 |
+
= show_section_dead(False)
|
95 |
+
section_wounded, radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
96 |
+
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
97 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
98 |
+
behavior_checkbox, behavior_text, \
|
99 |
+
physical_boxes_wounded, \
|
100 |
+
checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded, \
|
101 |
+
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
|
102 |
+
fe_name_recipient_wounded, fe_collection_ref_wounded \
|
103 |
+
= show_section_wounded(False)
|
104 |
|
105 |
+
# ---------------------------------------------------------
|
106 |
+
# ---------------------------------------------------------
|
107 |
+
# ---------------------------------------------------------
|
108 |
+
# Dead Button Logic
|
109 |
+
partial_show_section_dead = partial(show_section_dead, True)
|
110 |
+
partial_hide_section_wounded = partial(show_section_wounded, False)
|
111 |
+
butt_dead.click(partial_show_section_dead,
|
112 |
+
inputs=None,
|
113 |
+
outputs=[section_dead,
|
114 |
+
radio_circumstance_dead, radio_physical_dead,
|
115 |
+
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
116 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
|
117 |
+
physical_boxes_dead, \
|
118 |
+
checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead, \
|
119 |
+
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
|
120 |
+
fe_name_recipient_dead, fe_collection_ref_dead \
|
121 |
+
])
|
122 |
+
butt_dead.click(partial_hide_section_wounded,
|
123 |
+
inputs=None,
|
124 |
+
outputs=[section_wounded,
|
125 |
+
radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,
|
126 |
+
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
127 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
|
128 |
+
behavior_checkbox, behavior_text,
|
129 |
+
physical_boxes_wounded, \
|
130 |
+
checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded, \
|
131 |
+
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
|
132 |
+
fe_name_recipient_wounded, fe_collection_ref_wounded \
|
133 |
+
])
|
134 |
|
135 |
+
# ---------------------------------------------------------
|
136 |
+
# Wounded Button Logic
|
137 |
+
partial_show_section_wounded = partial(show_section_wounded, True)
|
138 |
+
partial_hide_section_dead = partial(show_section_dead, False)
|
139 |
|
140 |
+
butt_wounded.click(partial_show_section_wounded,
|
141 |
+
inputs=None,
|
142 |
+
outputs=[section_wounded,
|
143 |
+
radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,
|
144 |
+
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
145 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
|
146 |
+
behavior_checkbox, behavior_text,
|
147 |
+
physical_boxes_wounded, \
|
148 |
+
checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded, \
|
149 |
+
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \
|
150 |
+
fe_name_recipient_wounded, fe_collection_ref_wounded \
|
151 |
+
])
|
152 |
+
butt_wounded.click(partial_hide_section_dead, inputs=None, outputs=[section_dead,
|
153 |
+
radio_circumstance_dead, radio_physical_dead,
|
154 |
+
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
155 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
|
156 |
+
physical_boxes_dead, \
|
157 |
+
checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead, \
|
158 |
+
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \
|
159 |
+
fe_name_recipient_dead, fe_collection_ref_dead \
|
160 |
+
])
|
161 |
+
# ---------------------------------------------------------
|
162 |
+
# ---------------------------------------------------------
|
163 |
+
# ---------------------------------------------------------
|
164 |
+
# ---------------------------------------------------------
|
165 |
+
# DEAD
|
166 |
+
# ---------------------------------------------------------
|
167 |
+
# Radio Circumstance Dead
|
168 |
+
radio_circumstance_dead.change(fn=show_circumstances,
|
169 |
+
inputs=[radio_circumstance_dead],
|
170 |
+
outputs=[button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
171 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead]
|
172 |
+
)
|
173 |
|
174 |
+
# Dropdowns Dead
|
175 |
+
button_collision_dead.click(dropdown_collision,
|
176 |
+
outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead])
|
177 |
+
button_deliberate_destruction_dead.click(dropdown_deliberate_destruction, outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead])
|
178 |
+
button_indirect_destruction_dead.click(dropdown_indirect_destruction, outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead])
|
179 |
+
button_natural_cause_dead.click(dropdown_natural_cause, outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead])
|
180 |
|
181 |
+
dropdown_dead.select(on_select, None, [dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead])
|
182 |
+
dropdown_level2_dead.select(on_select_dropdown_level2)
|
183 |
+
openfield_level2_dead.change(on_change_openfield_level2, inputs=[openfield_level2_dead])
|
184 |
+
dropdown_extra_level2_dead.select(on_select_dropdown_extra_level2)
|
185 |
+
# ---------------------------------------------------------
|
186 |
+
# Radio Physical Dead
|
187 |
+
radio_physical_dead.change(fn=show_physical,
|
188 |
+
inputs=[radio_physical_dead, gr.Text("dead", visible=False)],
|
189 |
+
outputs=[physical_boxes_dead])
|
190 |
|
191 |
+
# Checkbox Physical Dead
|
192 |
+
physical_boxes_dead.select(find_bounding_box,
|
193 |
+
inputs=[physical_boxes_dead, gr.Textbox(value="dead", visible=False)],
|
194 |
+
outputs=[checkbox_beak_dead, text_beak_dead,
|
195 |
+
checkbox_body_dead, text_body_dead,
|
196 |
+
checkbox_feathers_dead, text_feathers_dead,
|
197 |
+
checkbox_head_dead, text_head_dead,
|
198 |
+
checkbox_legs_dead, text_legs_dead
|
199 |
+
])
|
200 |
+
checkbox_beak_dead.select(on_select_body_part, inputs=[checkbox_beak_dead, gr.Text("beak", visible=False)])
|
201 |
+
checkbox_body_dead.select(on_select_body_part, inputs=[checkbox_body_dead, gr.Text("body", visible=False)])
|
202 |
+
checkbox_feathers_dead.select(on_select_body_part, inputs=[checkbox_feathers_dead, gr.Text("feathers", visible=False)])
|
203 |
+
checkbox_head_dead.select(on_select_body_part, inputs=[checkbox_head_dead, gr.Text("head", visible=False)])
|
204 |
+
checkbox_legs_dead.select(on_select_body_part, inputs=[checkbox_legs_dead, gr.Text("legs", visible=False)])
|
205 |
+
# ---------------------------------------------------------
|
206 |
+
# ---------------------------------------------------------
|
207 |
+
# ---------------------------------------------------------
|
208 |
+
# ---------------------------------------------------------
|
209 |
+
# WOUNDED
|
210 |
+
# ---------------------------------------------------------
|
211 |
+
# Radio Circumstance Wounded
|
212 |
+
radio_circumstance_wounded.change(fn=show_circumstances,
|
213 |
+
inputs=[radio_circumstance_wounded],
|
214 |
+
outputs=[button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
215 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded]
|
216 |
+
)
|
217 |
|
218 |
+
# Dropdowns Circumstance Wounded
|
219 |
+
button_collision_wounded.click(dropdown_collision,
|
220 |
+
outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
|
221 |
+
button_deliberate_destruction_wounded.click(dropdown_deliberate_destruction, outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
|
222 |
+
button_indirect_destruction_wounded.click(dropdown_indirect_destruction, outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
|
223 |
+
button_natural_cause_wounded.click(dropdown_natural_cause, outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
|
224 |
|
225 |
+
dropdown_wounded.select(on_select, None, [dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
|
226 |
+
dropdown_level2_wounded.select(on_select_dropdown_level2)
|
227 |
+
openfield_level2_wounded.change(on_change_openfield_level2, inputs=[openfield_level2_wounded])
|
228 |
+
dropdown_extra_level2_wounded.select(on_select_dropdown_extra_level2)
|
229 |
+
# ---------------------------------------------------------
|
230 |
+
# Radio Behavior Wounded
|
231 |
+
radio_behavior_wounded.change(fn=show_behavior,
|
232 |
+
inputs=[radio_behavior_wounded, gr.Text("wounded", visible=False)],
|
233 |
+
outputs=[behavior_checkbox, behavior_text])
|
234 |
+
behavior_checkbox.select(on_select_behavior,
|
235 |
+
inputs=[behavior_checkbox])
|
236 |
+
# ---------------------------------------------------------
|
237 |
+
# Radio Physical Wounded
|
238 |
+
radio_physical_wounded.change(fn=show_physical,
|
239 |
+
inputs=[radio_physical_wounded, gr.Text("wounded", visible=False)],
|
240 |
+
outputs=[physical_boxes_wounded])
|
241 |
|
242 |
+
# Checkbox Physical Wounded
|
243 |
+
physical_boxes_wounded.select(find_bounding_box,
|
244 |
+
inputs=[physical_boxes_wounded, gr.Textbox(value="wounded", visible=False)],
|
245 |
+
outputs=[checkbox_beak_wounded, text_beak_wounded,
|
246 |
+
checkbox_body_wounded, text_body_wounded,
|
247 |
+
checkbox_feathers_wounded, text_feathers_wounded,
|
248 |
+
checkbox_head_wounded, text_head_wounded,
|
249 |
+
checkbox_legs_wounded, text_legs_wounded
|
250 |
+
])
|
251 |
+
checkbox_beak_wounded.select(on_select_body_part, inputs=[checkbox_beak_wounded, gr.Text("beak", visible=False)])
|
252 |
+
checkbox_body_wounded.select(on_select_body_part, inputs=[checkbox_body_wounded, gr.Text("body", visible=False)])
|
253 |
+
checkbox_feathers_wounded.select(on_select_body_part, inputs=[checkbox_feathers_wounded, gr.Text("feathers", visible=False)])
|
254 |
+
checkbox_head_wounded.select(on_select_body_part, inputs=[checkbox_head_wounded, gr.Text("head", visible=False)])
|
255 |
+
checkbox_legs_wounded.select(on_select_body_part, inputs=[checkbox_legs_wounded, gr.Text("legs", visible=False)])
|
256 |
|
257 |
+
# ---------------------------------------------------------
|
258 |
+
# Follow Up Events Wounded
|
259 |
+
fe_collection_dropdown_wounded.select(save_fe, inputs=[fe_collection_dropdown_wounded, gr.Textbox("animal collected", visible=False)])
|
260 |
+
fe_recepient_dropdown_wounded.select(save_fe, inputs=[fe_recepient_dropdown_wounded, gr.Textbox("recipient", visible=False)])
|
261 |
+
fe_radio_dropdown_wounded.select(save_fe, inputs=[fe_radio_dropdown_wounded, gr.Textbox("radiography", visible=False)])
|
262 |
+
fe_answer_dropdown_wounded.select(save_fe, inputs=[fe_answer_dropdown_wounded, gr.Textbox("given answer", visible=False)])
|
263 |
+
fe_name_recipient_wounded.input(save_fe, inputs=[fe_name_recipient_wounded, gr.Textbox("recipient name", visible=False)])
|
264 |
+
fe_collection_ref_wounded.input(save_fe, inputs=[fe_collection_ref_wounded, gr.Textbox("collection reference", visible=False)])
|
265 |
|
266 |
+
# ---------------------------------------------------------
|
267 |
+
# Follow Up Events Dead
|
268 |
+
fe_collection_dropdown_dead.select(save_fe, inputs=[fe_collection_dropdown_dead, gr.Textbox("animal collected", visible=False)])
|
269 |
+
fe_recepient_dropdown_dead.select(save_fe, inputs=[fe_recepient_dropdown_dead, gr.Textbox("recipient", visible=False)])
|
270 |
+
fe_radio_dropdown_dead.select(save_fe, inputs=[fe_radio_dropdown_dead, gr.Textbox("radiography", visible=False)])
|
271 |
+
fe_answer_dropdown_dead.select(save_fe, inputs=[fe_answer_dropdown_dead, gr.Textbox("given answer", visible=False)])
|
272 |
+
fe_name_recipient_dead.input(save_fe, inputs=[fe_name_recipient_dead, gr.Textbox("recipient name", visible=False)])
|
273 |
+
fe_collection_ref_dead.input(save_fe, inputs=[fe_collection_ref_dead, gr.Textbox("collection reference", visible=False)])
|
274 |
|
275 |
+
# ---------------------------------------------------------
|
276 |
+
# Error Box
|
277 |
+
error_box = gr.Text(value=None, visible=False)
|
278 |
|
279 |
+
# ---------------------------------------------------------
|
280 |
+
# Add One Individual's Data to the Dataframe
|
281 |
+
# And Allow clearing of all previous output
|
282 |
+
with gr.Row():
|
283 |
+
button_df = gr.Button("Submit Animal Report", scale = 3)
|
284 |
+
button_clear = gr.ClearButton(scale = 1,
|
285 |
+
components=[
|
286 |
+
camera,
|
287 |
+
location, identified_location,
|
288 |
+
#dead reset
|
289 |
+
radio_circumstance_dead, radio_physical_dead,
|
290 |
+
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
291 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead,
|
292 |
+
physical_boxes_dead,
|
293 |
+
checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead,
|
294 |
+
fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead,
|
295 |
+
fe_name_recipient_dead, fe_collection_ref_dead,
|
296 |
+
#wounded reset
|
297 |
+
radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,
|
298 |
+
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,
|
299 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,
|
300 |
+
behavior_checkbox, behavior_text,
|
301 |
+
physical_boxes_wounded,
|
302 |
+
checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded,
|
303 |
+
fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded,
|
304 |
+
fe_name_recipient_wounded, fe_collection_ref_wounded,
|
305 |
+
error_box
|
306 |
+
])
|
307 |
+
button_close = gr.Button("Back to Display", scale = 1)
|
308 |
|
309 |
|
310 |
+
# ---------------------------------------------------------
|
311 |
+
# Button Click Logic
|
312 |
+
button_clear.click()
|
313 |
+
button_clear.click(hide_physical,
|
314 |
+
outputs=[checkbox_beak_wounded, text_beak_wounded, checkbox_body_wounded, text_body_wounded, checkbox_feathers_wounded, text_feathers_wounded, checkbox_head_wounded, text_head_wounded, checkbox_legs_wounded, text_legs_wounded])
|
315 |
+
button_clear.click(hide_physical,
|
316 |
+
outputs=[checkbox_beak_dead, text_beak_dead, checkbox_body_dead, text_body_dead, checkbox_feathers_dead, text_feathers_dead, checkbox_head_dead, text_head_dead, checkbox_legs_dead, text_legs_dead])
|
317 |
|
318 |
+
button_clear.click(reset_error_box, inputs=[error_box], outputs=[error_box])
|
319 |
+
button_clear.click(reset_json)
|
320 |
|
321 |
+
button_df.click(save_display_individual,
|
322 |
+
inputs=[gallery, df, error_box],
|
323 |
+
outputs=[gallery, df, error_box]
|
324 |
+
)
|
325 |
+
button_close.click(lambda: Modal(visible=False), None, modal)
|
326 |
|
327 |
+
# ---------------------------------------------------------
|
328 |
+
# Event Functions of the landing page buttons
|
329 |
+
show_modal.click(lambda: Modal(visible=True), None, modal)
|
330 |
+
show_modal.click(create_json_one_individual)
|
331 |
+
show_modal.click(create_tmp)
|
332 |
+
#submit_button.click(save_and_rest_df, inputs=[df], outputs=[df])
|
333 |
|
|
|
|
|
334 |
|
|
|
|
|
335 |
if __name__ == "__main__":
|
336 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|