feat: tabs for each animal input
Browse files- app/main_async.py +155 -0
- app/main_dynamic_tabs.py +134 -0
- app/{main.py → main_old.py} +57 -22
- app/main_test.py +0 -68
app/main_async.py
ADDED
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.py → main_old.py}
RENAMED
@@ -40,31 +40,67 @@ with gr.Blocks(theme=theme, css=css) as demo:
|
|
40 |
#to submit it
|
41 |
submit_location = gr.Button("Get GPS Coordinates", visible=True, interactive=True, scale=3)
|
42 |
submit_location.click(get_location, inputs=[location], outputs=[identified_location])
|
43 |
-
|
44 |
# ---------------------------------------------------------
|
45 |
-
#
|
46 |
-
|
47 |
-
|
48 |
-
with gr.
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
# ---------------------------------------------------------
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
behavior_checkbox, behavior_text, \
|
64 |
-
physical_boxes_wounded, \
|
65 |
-
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs \
|
66 |
-
= show_section_wounded(False)
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
# ---------------------------------------------------------
|
69 |
# Dead Button Logic
|
70 |
partial_show_section_dead = partial(show_section_dead, True)
|
@@ -84,7 +120,6 @@ with gr.Blocks(theme=theme, css=css) as demo:
|
|
84 |
behavior_checkbox, behavior_text,
|
85 |
physical_boxes_wounded,
|
86 |
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs
|
87 |
-
|
88 |
])
|
89 |
# ---------------------------------------------------------
|
90 |
# Wounded Button Logic
|
|
|
40 |
#to submit it
|
41 |
submit_location = gr.Button("Get GPS Coordinates", visible=True, interactive=True, scale=3)
|
42 |
submit_location.click(get_location, inputs=[location], outputs=[identified_location])
|
43 |
+
|
44 |
# ---------------------------------------------------------
|
45 |
+
# ---------------------------------------------------------
|
46 |
+
# ---------------------------------------------------------
|
47 |
+
# ---------------------------------------------------------
|
48 |
+
with gr.Tab("Animal 1"):
|
49 |
+
# ---------------------------------------------------------
|
50 |
+
# Dead and Wounded Buttons
|
51 |
+
gr.Markdown("## The State of the Animal", label="Title")
|
52 |
+
gr.Markdown("Please tell us if the animal was wounded or dead.", label="description")
|
53 |
+
with gr.Row() as block_form:
|
54 |
+
with gr.Column(scale=1):
|
55 |
+
butt_wounded = gr.Button("Wounded", elem_id="wounded")
|
56 |
+
with gr.Column(scale=1):
|
57 |
+
butt_dead = gr.Button("Dead", elem_id="dead")
|
58 |
|
59 |
+
# ---------------------------------------------------------
|
60 |
+
# Initiate sections
|
61 |
+
section_dead, \
|
62 |
+
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
|
63 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead \
|
64 |
+
= show_section_dead(False)
|
65 |
+
section_wounded, radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
66 |
+
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
67 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
68 |
+
behavior_checkbox, behavior_text, \
|
69 |
+
physical_boxes_wounded, \
|
70 |
+
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs \
|
71 |
+
= show_section_wounded(False)
|
72 |
+
|
73 |
+
# ---------------------------------------------------------
|
74 |
+
# ---------------------------------------------------------
|
75 |
+
# ---------------------------------------------------------
|
76 |
+
with gr.Tab("Animal 2"):
|
77 |
# ---------------------------------------------------------
|
78 |
+
# Dead and Wounded Buttons
|
79 |
+
gr.Markdown("## The State of the Animal", label="Title")
|
80 |
+
gr.Markdown("Please tell us if the animal was wounded or dead.", label="description")
|
81 |
+
with gr.Row() as block_form:
|
82 |
+
with gr.Column(scale=1):
|
83 |
+
butt_wounded = gr.Button("Wounded", elem_id="wounded")
|
84 |
+
with gr.Column(scale=1):
|
85 |
+
butt_dead = gr.Button("Dead", elem_id="dead")
|
|
|
|
|
|
|
|
|
86 |
|
87 |
+
# ---------------------------------------------------------
|
88 |
+
# Initiate sections
|
89 |
+
section_dead, \
|
90 |
+
button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \
|
91 |
+
dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead \
|
92 |
+
= show_section_dead(False)
|
93 |
+
section_wounded, radio_cause_wounded, radio_behavior_wounded, radio_physical_wounded, \
|
94 |
+
button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \
|
95 |
+
dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \
|
96 |
+
behavior_checkbox, behavior_text, \
|
97 |
+
physical_boxes_wounded, \
|
98 |
+
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs \
|
99 |
+
= show_section_wounded(False)
|
100 |
+
# ---------------------------------------------------------
|
101 |
+
# ---------------------------------------------------------
|
102 |
+
# ---------------------------------------------------------
|
103 |
+
|
104 |
# ---------------------------------------------------------
|
105 |
# Dead Button Logic
|
106 |
partial_show_section_dead = partial(show_section_dead, True)
|
|
|
120 |
behavior_checkbox, behavior_text,
|
121 |
physical_boxes_wounded,
|
122 |
checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs
|
|
|
123 |
])
|
124 |
# ---------------------------------------------------------
|
125 |
# Wounded Button Logic
|
app/main_test.py
DELETED
@@ -1,68 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
|
3 |
-
# Function that processes the Textbox input and generates new CheckboxGroups
|
4 |
-
def generate_checkbox_groups(textbox_input):
|
5 |
-
try:
|
6 |
-
num_groups = int(textbox_input)
|
7 |
-
except ValueError:
|
8 |
-
return "Please enter a valid number."
|
9 |
-
|
10 |
-
# Dynamically create a list of CheckboxGroups
|
11 |
-
checkbox_groups = []
|
12 |
-
for i in range(num_groups):
|
13 |
-
checkbox_groups.append(gr.CheckboxGroup(
|
14 |
-
choices=["Option 1", "Option 2", "Option 3"],
|
15 |
-
label=f"Checkbox Group {i + 1}",
|
16 |
-
interactive=True
|
17 |
-
))
|
18 |
-
|
19 |
-
return checkbox_groups
|
20 |
-
|
21 |
-
# Function to process the selections of the dynamically created CheckboxGroups
|
22 |
-
def process_selections(*checkbox_values):
|
23 |
-
results = []
|
24 |
-
for i, selections in enumerate(checkbox_values):
|
25 |
-
selected_options = ', '.join(selections) if selections else 'None'
|
26 |
-
results.append(f"Selected options for group {i + 1}: {selected_options}")
|
27 |
-
|
28 |
-
return "\n".join(results)
|
29 |
-
|
30 |
-
with gr.Blocks() as demo:
|
31 |
-
# Textbox for user input to specify the number of CheckboxGroups
|
32 |
-
textbox = gr.Textbox(label="Enter the number of Checkbox Groups to create")
|
33 |
-
|
34 |
-
# Button to trigger the generation of CheckboxGroups
|
35 |
-
generate_button = gr.Button("Generate Checkbox Groups")
|
36 |
-
|
37 |
-
# A placeholder for the dynamically generated CheckboxGroups
|
38 |
-
dynamic_checkbox_groups = gr.Column()
|
39 |
-
|
40 |
-
# Output Textbox to display the results
|
41 |
-
output = gr.Textbox(label="Output")
|
42 |
-
|
43 |
-
# Generate CheckboxGroups based on Textbox input
|
44 |
-
def update_dynamic_groups(textbox_value):
|
45 |
-
groups = generate_checkbox_groups(textbox_value)
|
46 |
-
dynamic_checkbox_groups.children = groups
|
47 |
-
return dynamic_checkbox_groups
|
48 |
-
|
49 |
-
generate_button.click(
|
50 |
-
fn=update_dynamic_groups,
|
51 |
-
inputs=textbox,
|
52 |
-
outputs=dynamic_checkbox_groups
|
53 |
-
)
|
54 |
-
|
55 |
-
# Button to process selections from the dynamically generated CheckboxGroups
|
56 |
-
process_button = gr.Button("Submit Selections")
|
57 |
-
|
58 |
-
# Process the selections when the second button is clicked
|
59 |
-
def process_dynamic_groups(*checkbox_groups):
|
60 |
-
return process_selections(*checkbox_groups)
|
61 |
-
|
62 |
-
process_button.click(
|
63 |
-
fn=process_dynamic_groups,
|
64 |
-
inputs=dynamic_checkbox_groups.children, # Unpack the dynamically generated groups
|
65 |
-
outputs=output
|
66 |
-
)
|
67 |
-
|
68 |
-
demo.launch(server_name="0.0.0.0")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|