feat: begin modal refactor and save individual location data as json
Browse files- .gitignore +1 -0
- app/main_async.py +0 -155
- app/main_dynamic_tabs.py +0 -134
- app/main_modal.py +37 -0
- app/main_multianimal.py +73 -0
- app/maps.py +13 -7
- app/utils_json.py +16 -0
- requirements.txt +1 -0
.gitignore
CHANGED
@@ -7,6 +7,7 @@ __pycache__/
|
|
7 |
|
8 |
#Data
|
9 |
test/data/**
|
|
|
10 |
|
11 |
# C extensions
|
12 |
*.so
|
|
|
7 |
|
8 |
#Data
|
9 |
test/data/**
|
10 |
+
data/**
|
11 |
|
12 |
# C extensions
|
13 |
*.so
|
app/main_async.py
DELETED
@@ -1,155 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import asyncio
|
3 |
-
from functools import partial
|
4 |
-
|
5 |
-
from dead import show_section_dead
|
6 |
-
from wounded import show_section_wounded
|
7 |
-
from circumstances_dropdowns import *
|
8 |
-
|
9 |
-
def partial_show_section_wounded():
|
10 |
-
section_dead, \
|
11 |
-
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
|
12 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead \
|
13 |
-
= show_section_dead(False)
|
14 |
-
section_wounded, radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
15 |
-
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
16 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
17 |
-
behavior_checkbox, behavior_text, \
|
18 |
-
physical_boxes_wounded, \
|
19 |
-
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs \
|
20 |
-
= show_section_wounded(True)
|
21 |
-
return section_dead, \
|
22 |
-
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
|
23 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
|
24 |
-
section_wounded, radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
25 |
-
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
26 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
27 |
-
behavior_checkbox, behavior_text, \
|
28 |
-
physical_boxes_wounded, \
|
29 |
-
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs
|
30 |
-
|
31 |
-
def partial_show_section_dead():
|
32 |
-
section_wounded, radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
33 |
-
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
34 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
35 |
-
behavior_checkbox, behavior_text, \
|
36 |
-
physical_boxes_wounded, \
|
37 |
-
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs \
|
38 |
-
= show_section_wounded(False)
|
39 |
-
# Your logic here to show the sections and buttons
|
40 |
-
section_dead, \
|
41 |
-
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
|
42 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead \
|
43 |
-
= show_section_dead(True)
|
44 |
-
return section_dead, \
|
45 |
-
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
|
46 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
|
47 |
-
section_wounded, radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
48 |
-
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
49 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
50 |
-
behavior_checkbox, behavior_text, \
|
51 |
-
physical_boxes_wounded, \
|
52 |
-
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs \
|
53 |
-
|
54 |
-
|
55 |
-
def create_animal_tab(num_animals):
|
56 |
-
for animal_index in range(int(num_animals)):
|
57 |
-
with gr.Tab(f"Animal {animal_index + 1}"):
|
58 |
-
# ---------------------------------------------------------
|
59 |
-
# Dead and Wounded Buttons
|
60 |
-
gr.Markdown("## The State of the Animal", label="Title")
|
61 |
-
gr.Markdown("Please tell us if the animal was wounded or dead.", label="description")
|
62 |
-
with gr.Row() as block_form:
|
63 |
-
with gr.Column(scale=1):
|
64 |
-
butt_wounded = gr.Button("Wounded", elem_id=f"wounded_{animal_index + 1}")
|
65 |
-
with gr.Column(scale=1):
|
66 |
-
butt_dead = gr.Button("Dead", elem_id=f"dead_{animal_index + 1}")
|
67 |
-
|
68 |
-
# ---------------------------------------------------------
|
69 |
-
# Initiate sections
|
70 |
-
section_dead, \
|
71 |
-
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
|
72 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead \
|
73 |
-
= show_section_dead(False)
|
74 |
-
|
75 |
-
section_wounded, radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
76 |
-
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
77 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
78 |
-
behavior_checkbox, behavior_text, \
|
79 |
-
physical_boxes_wounded, \
|
80 |
-
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs \
|
81 |
-
= show_section_wounded(False)
|
82 |
-
|
83 |
-
# ---------------------------------------------------------
|
84 |
-
# Dead Button Logic for the current tab
|
85 |
-
butt_dead.click(partial(partial_show_section_dead),
|
86 |
-
inputs=None,
|
87 |
-
outputs=[section_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 |
-
section_wounded, radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
91 |
-
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
92 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
93 |
-
behavior_checkbox, behavior_text, \
|
94 |
-
physical_boxes_wounded, \
|
95 |
-
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs \
|
96 |
-
])
|
97 |
-
butt_wounded.click(partial(partial_show_section_wounded),
|
98 |
-
inputs=None,
|
99 |
-
outputs=[section_dead,
|
100 |
-
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
101 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead,
|
102 |
-
section_wounded, radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
103 |
-
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
104 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
105 |
-
behavior_checkbox, behavior_text, \
|
106 |
-
physical_boxes_wounded, \
|
107 |
-
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs \
|
108 |
-
])
|
109 |
-
# ---------------------------------------------------------
|
110 |
-
# Dead Button Logic for the current tab
|
111 |
-
button_collision_dead.click(dropdown_collision,
|
112 |
-
outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead])
|
113 |
-
|
114 |
-
|
115 |
-
# Initialize global variables
|
116 |
-
NUM_ANIMALS = 1
|
117 |
-
VARIABLE_CHANGE_EVENT = asyncio.Event()
|
118 |
-
|
119 |
-
# Function to change the global variable
|
120 |
-
def change_num_animal(num_animals):
|
121 |
-
NUM_ANIMALS = int(num_animals)
|
122 |
-
print(f"Number animals: {NUM_ANIMALS}")
|
123 |
-
VARIABLE_CHANGE_EVENT.set()
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
# Async function that waits for the global variable to change and then creates tabs
|
128 |
-
async def tabbify():
|
129 |
-
while True:
|
130 |
-
await VARIABLE_CHANGE_EVENT.wait()
|
131 |
-
print("Creating tabs!")
|
132 |
-
# Simulate tab creation logic
|
133 |
-
create_animal_tab(NUM_ANIMALS)
|
134 |
-
|
135 |
-
|
136 |
-
async def main():
|
137 |
-
|
138 |
-
asyncio.create_task(tabbify())
|
139 |
-
|
140 |
-
with gr.Blocks() as demo:
|
141 |
-
|
142 |
-
|
143 |
-
# Input box to enter the number of tabs
|
144 |
-
num_tabs = gr.Textbox(label="Enter number of animals:", value="1", interactive=True)
|
145 |
-
|
146 |
-
# Button to trigger the generation of tabs
|
147 |
-
generate_button = gr.Button("Generate Tabs")
|
148 |
-
|
149 |
-
# When the button is clicked, change the global variable
|
150 |
-
generate_button.click(fn=change_num_animal, inputs=[num_tabs], outputs=[])
|
151 |
-
demo.launch(server_name="0.0.0.0", server_port=5000)
|
152 |
-
|
153 |
-
# Run the main function
|
154 |
-
asyncio.run(main())
|
155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/main_dynamic_tabs.py
DELETED
@@ -1,134 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from functools import partial
|
3 |
-
|
4 |
-
from dead import show_section_dead
|
5 |
-
from wounded import show_section_wounded
|
6 |
-
from circumstances_dropdowns import *
|
7 |
-
|
8 |
-
# Define the show_section_dead and partial_show_section_dead functions as needed
|
9 |
-
|
10 |
-
def partial_show_section_wounded():
|
11 |
-
section_dead, \
|
12 |
-
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
|
13 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead \
|
14 |
-
= show_section_dead(False)
|
15 |
-
section_wounded, radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
16 |
-
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
17 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
18 |
-
behavior_checkbox, behavior_text, \
|
19 |
-
physical_boxes_wounded, \
|
20 |
-
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs \
|
21 |
-
= show_section_wounded(True)
|
22 |
-
return section_dead, \
|
23 |
-
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
|
24 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
|
25 |
-
section_wounded, radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
26 |
-
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
27 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
28 |
-
behavior_checkbox, behavior_text, \
|
29 |
-
physical_boxes_wounded, \
|
30 |
-
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs
|
31 |
-
|
32 |
-
def partial_show_section_dead():
|
33 |
-
section_wounded, radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
34 |
-
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
35 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
36 |
-
behavior_checkbox, behavior_text, \
|
37 |
-
physical_boxes_wounded, \
|
38 |
-
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs \
|
39 |
-
= show_section_wounded(False)
|
40 |
-
# Your logic here to show the sections and buttons
|
41 |
-
section_dead, \
|
42 |
-
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
|
43 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead \
|
44 |
-
= show_section_dead(True)
|
45 |
-
return section_dead, \
|
46 |
-
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
|
47 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \
|
48 |
-
section_wounded, radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
49 |
-
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
50 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
51 |
-
behavior_checkbox, behavior_text, \
|
52 |
-
physical_boxes_wounded, \
|
53 |
-
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs \
|
54 |
-
|
55 |
-
|
56 |
-
def create_animal_tab(num_animals):
|
57 |
-
for animal_index in range(int(num_animals)):
|
58 |
-
with gr.Tab(f"Animal {animal_index + 1}"):
|
59 |
-
# ---------------------------------------------------------
|
60 |
-
# Dead and Wounded Buttons
|
61 |
-
gr.Markdown("## The State of the Animal", label="Title")
|
62 |
-
gr.Markdown("Please tell us if the animal was wounded or dead.", label="description")
|
63 |
-
with gr.Row() as block_form:
|
64 |
-
with gr.Column(scale=1):
|
65 |
-
butt_wounded = gr.Button("Wounded", elem_id=f"wounded_{animal_index + 1}")
|
66 |
-
with gr.Column(scale=1):
|
67 |
-
butt_dead = gr.Button("Dead", elem_id=f"dead_{animal_index + 1}")
|
68 |
-
|
69 |
-
# ---------------------------------------------------------
|
70 |
-
# Initiate sections
|
71 |
-
section_dead, \
|
72 |
-
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
|
73 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead \
|
74 |
-
= show_section_dead(False)
|
75 |
-
|
76 |
-
section_wounded, radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
77 |
-
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
78 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
79 |
-
behavior_checkbox, behavior_text, \
|
80 |
-
physical_boxes_wounded, \
|
81 |
-
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs \
|
82 |
-
= show_section_wounded(False)
|
83 |
-
|
84 |
-
# ---------------------------------------------------------
|
85 |
-
# Dead Button Logic for the current tab
|
86 |
-
butt_dead.click(partial(partial_show_section_dead),
|
87 |
-
inputs=None,
|
88 |
-
outputs=[section_dead,
|
89 |
-
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
90 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead,
|
91 |
-
section_wounded, radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
92 |
-
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
93 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
94 |
-
behavior_checkbox, behavior_text, \
|
95 |
-
physical_boxes_wounded, \
|
96 |
-
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs \
|
97 |
-
])
|
98 |
-
butt_wounded.click(partial(partial_show_section_wounded),
|
99 |
-
inputs=None,
|
100 |
-
outputs=[section_dead,
|
101 |
-
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,
|
102 |
-
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead,
|
103 |
-
section_wounded, radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
104 |
-
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
105 |
-
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
106 |
-
behavior_checkbox, behavior_text, \
|
107 |
-
physical_boxes_wounded, \
|
108 |
-
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs \
|
109 |
-
])
|
110 |
-
# ---------------------------------------------------------
|
111 |
-
# Dead Button Logic for the current tab
|
112 |
-
button_collision_dead.click(dropdown_collision,
|
113 |
-
outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead])
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
with gr.Blocks() as demo:
|
118 |
-
|
119 |
-
# Input box to enter the number of tabs
|
120 |
-
num_tabs = gr.Textbox(label="Enter number of animals:",
|
121 |
-
value="1",
|
122 |
-
interactive=True)
|
123 |
-
|
124 |
-
# Button to trigger the generation of tabs
|
125 |
-
generate_button = gr.Button("Generate Tabs")
|
126 |
-
|
127 |
-
# When the button is clicked, generate tabs
|
128 |
-
# generate_button.click(fn=create_animal_tab,
|
129 |
-
# inputs=[num_tabs])
|
130 |
-
create_animal_tab(num_tabs)
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
demo.launch(server_name="0.0.0.0", server_port=5500)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/main_modal.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gradio_modal import Modal
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
def save_input(input, df):
|
6 |
+
#input_value = str(input)
|
7 |
+
df_values = np.array(df) # handle empty dataframe case
|
8 |
+
new_row = [input, 0, input] # default 'age' as 0 for now
|
9 |
+
df_values = np.vstack([df_values, new_row])
|
10 |
+
df = gr.DataFrame(value=df_values)
|
11 |
+
return df
|
12 |
+
|
13 |
+
with gr.Blocks() as demo:
|
14 |
+
with gr.Tab("Tab 1"):
|
15 |
+
show_btn = gr.Button("Show Modal")
|
16 |
+
df = gr.Dataframe(
|
17 |
+
headers=["name", "age", "gender"],
|
18 |
+
#datatype=["str", "number", "str"],
|
19 |
+
row_count=1,
|
20 |
+
col_count=(3, "fixed"),
|
21 |
+
)
|
22 |
+
show_markdown = gr.Markdown("This is a markdown")
|
23 |
+
with Modal(visible=False) as modal:
|
24 |
+
input = gr.Textbox(label="Input 1", interactive=True)
|
25 |
+
button = gr.Button("Click me")
|
26 |
+
button.click(save_input,
|
27 |
+
inputs=[input, df],
|
28 |
+
outputs=[df])
|
29 |
+
button.click(lambda: Modal(visible=False), None, modal)
|
30 |
+
show_btn.click(lambda: Modal(visible=True), None, modal)
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
if __name__ == "__main__":
|
37 |
+
demo.launch(server_name="0.0.0.0", server_port=3333)
|
app/main_multianimal.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gradio_modal import Modal
|
3 |
+
import numpy as np
|
4 |
+
from maps import get_location
|
5 |
+
from utils_json import *
|
6 |
+
|
7 |
+
|
8 |
+
def save_input(input, df):
|
9 |
+
#input_value = str(input)
|
10 |
+
df_values = np.array(df) # handle empty dataframe case
|
11 |
+
new_row = [input, 0, input] # default 'age' as 0 for now
|
12 |
+
df_values = np.vstack([df_values, new_row])
|
13 |
+
df = gr.DataFrame(value=df_values)
|
14 |
+
return df
|
15 |
+
|
16 |
+
with gr.Blocks() as demo:
|
17 |
+
# with gr.Tab("Tab 1"):
|
18 |
+
show_btn = gr.Button("Show Modal")
|
19 |
+
df = gr.Dataframe(
|
20 |
+
headers=["image", "location"],
|
21 |
+
#datatype=["str", "number", "str"],
|
22 |
+
row_count=1,
|
23 |
+
#col_count=(3, "fixed"),
|
24 |
+
)
|
25 |
+
show_markdown = gr.Markdown("This is a markdown")
|
26 |
+
with Modal(visible=False) as modal:
|
27 |
+
input = gr.Textbox(label="Input 1", interactive=True)
|
28 |
+
# ---------------------------------------------------------
|
29 |
+
# Intro Text
|
30 |
+
with gr.Row():
|
31 |
+
with gr.Column(scale=1):
|
32 |
+
title = gr.Markdown("# Welcome to Digiwild", label="Title")
|
33 |
+
description = gr.Markdown("Please record your wildlife observations here !", label="description")
|
34 |
+
|
35 |
+
# ---------------------------------------------------------
|
36 |
+
# Camera
|
37 |
+
with gr.Row():
|
38 |
+
#with gr.Column(scale=1):
|
39 |
+
camera = gr.Image(elem_id="image")
|
40 |
+
|
41 |
+
# ---------------------------------------------------------
|
42 |
+
# Location
|
43 |
+
#with gr.Row():
|
44 |
+
with gr.Column(scale=1):
|
45 |
+
location = gr.Textbox(visible=True, interactive=True, label="Location of Sighting")
|
46 |
+
#display location processing
|
47 |
+
identified_location= gr.Textbox(visible=False, interactive=False,
|
48 |
+
label="Identified GPS Location")
|
49 |
+
with gr.Row():
|
50 |
+
#to clear it
|
51 |
+
clear_location = gr.ClearButton(components=[location], visible=True, interactive=True, scale=1
|
52 |
+
)
|
53 |
+
clear_location.click()
|
54 |
+
#to submit it
|
55 |
+
submit_location = gr.Button("Get GPS Coordinates", visible=True, interactive=True, scale=3)
|
56 |
+
submit_location.click(get_location, inputs=[location], outputs=[identified_location])
|
57 |
+
|
58 |
+
# ---------------------------------------------------------
|
59 |
+
|
60 |
+
button = gr.Button("Click me")
|
61 |
+
button.click(save_input,
|
62 |
+
inputs=[input, df],
|
63 |
+
outputs=[df])
|
64 |
+
button.click(lambda: Modal(visible=False), None, modal)
|
65 |
+
show_btn.click(lambda: Modal(visible=True), None, modal)
|
66 |
+
show_btn.click(create_json)
|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
+
|
71 |
+
|
72 |
+
if __name__ == "__main__":
|
73 |
+
demo.launch(server_name="0.0.0.0", server_port=3333)
|
app/maps.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1 |
from geopy.geocoders import Nominatim
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
def get_location(address):
|
5 |
-
try:
|
6 |
# calling the Nominatim tool
|
7 |
loc = Nominatim(user_agent="GetLoc")
|
8 |
|
@@ -12,6 +13,11 @@ def get_location(address):
|
|
12 |
# latitude and longitude
|
13 |
lat = getLoc.latitude
|
14 |
lon = getLoc.longitude
|
|
|
|
|
|
|
|
|
|
|
15 |
#display location processing
|
16 |
value = "Latitude = " + str(lat) + "\n" + "Longitude = " + str(lon)
|
17 |
identified_location= gr.Textbox(visible=True, interactive=False,
|
@@ -19,9 +25,9 @@ def get_location(address):
|
|
19 |
value=value)
|
20 |
return identified_location
|
21 |
|
22 |
-
except:
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
1 |
from geopy.geocoders import Nominatim
|
2 |
import gradio as gr
|
3 |
+
from utils_json import add_data_to_individual
|
4 |
|
5 |
def get_location(address):
|
6 |
+
# try:
|
7 |
# calling the Nominatim tool
|
8 |
loc = Nominatim(user_agent="GetLoc")
|
9 |
|
|
|
13 |
# latitude and longitude
|
14 |
lat = getLoc.latitude
|
15 |
lon = getLoc.longitude
|
16 |
+
|
17 |
+
# Save values
|
18 |
+
add_data_to_individual("latitude", lat)
|
19 |
+
add_data_to_individual("longitude", lon)
|
20 |
+
|
21 |
#display location processing
|
22 |
value = "Latitude = " + str(lat) + "\n" + "Longitude = " + str(lon)
|
23 |
identified_location= gr.Textbox(visible=True, interactive=False,
|
|
|
25 |
value=value)
|
26 |
return identified_location
|
27 |
|
28 |
+
# except:
|
29 |
+
# error = "Please try another less precise location."
|
30 |
+
# identified_location= gr.Textbox(visible=True, interactive=False,
|
31 |
+
# label="Identified GPS Location",
|
32 |
+
# value=error)
|
33 |
+
# return identified_location
|
app/utils_json.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
|
3 |
+
def create_json(one_individual={}):
|
4 |
+
# Serializing json
|
5 |
+
one_individual = json.dumps(one_individual, indent=4)
|
6 |
+
# Writing to sample.json
|
7 |
+
with open("data/one_individual.json", "w") as outfile:
|
8 |
+
outfile.write(one_individual)
|
9 |
+
|
10 |
+
def add_data_to_individual(key, value):
|
11 |
+
with open("data/one_individual.json", 'r') as openfile:
|
12 |
+
# Reading from json file
|
13 |
+
one_individual = json.load(openfile)
|
14 |
+
one_individual[key] = value
|
15 |
+
create_json(one_individual)
|
16 |
+
|
requirements.txt
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
gradio
|
|
|
2 |
geopy
|
3 |
geopandas
|
4 |
pillow
|
|
|
1 |
gradio
|
2 |
+
gradio_modal
|
3 |
geopy
|
4 |
geopandas
|
5 |
pillow
|