feat: follow up events section with config
Browse files- app/config_utils.py +14 -0
- app/dead.py +5 -1
- app/dropdowns.py +3 -14
- app/followup_events.py +16 -0
- app/main.py +3 -0
- app/top_section.py +0 -1
- app/wounded.py +5 -2
app/config_utils.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import os
|
3 |
+
|
4 |
+
def load_config(file_path):
|
5 |
+
with open(file_path) as f:
|
6 |
+
config = json.load(f)
|
7 |
+
return config
|
8 |
+
|
9 |
+
def get_custom_config_dropdowns(config_path):
|
10 |
+
path = os.getcwd()
|
11 |
+
dropdown_config_path = path + config_path
|
12 |
+
dropdown_config = load_config(dropdown_config_path)
|
13 |
+
return dropdown_config
|
14 |
+
|
app/dead.py
CHANGED
@@ -1,12 +1,16 @@
|
|
1 |
import gradio as gr
|
2 |
from top_section import create_top_section, create_dropdown
|
|
|
3 |
|
4 |
def show_section_dead(visible):
|
5 |
with gr.Column(visible=visible) as section_dead:
|
6 |
gr.Markdown("# Dead Animal")
|
7 |
-
gr.Markdown("Please describe the cause of death")
|
8 |
|
9 |
image_row, button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause = create_top_section(visible)
|
10 |
dropdown_row, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_dropdown(visible)
|
|
|
|
|
|
|
11 |
|
12 |
return section_dead, button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2
|
|
|
1 |
import gradio as gr
|
2 |
from top_section import create_top_section, create_dropdown
|
3 |
+
from followup_events import create_followup_section
|
4 |
|
5 |
def show_section_dead(visible):
|
6 |
with gr.Column(visible=visible) as section_dead:
|
7 |
gr.Markdown("# Dead Animal")
|
8 |
+
gr.Markdown("## Please describe the cause of death")
|
9 |
|
10 |
image_row, button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause = create_top_section(visible)
|
11 |
dropdown_row, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_dropdown(visible)
|
12 |
+
|
13 |
+
gr.Markdown("## Follow-up Events")
|
14 |
+
create_followup_section()
|
15 |
|
16 |
return section_dead, button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2
|
app/dropdowns.py
CHANGED
@@ -1,21 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import os
|
4 |
|
5 |
-
def load_config(file_path):
|
6 |
-
with open(file_path) as f:
|
7 |
-
config = json.load(f)
|
8 |
-
return config
|
9 |
-
|
10 |
-
def get_custom_config_dropdowns():
|
11 |
-
path = os.getcwd()
|
12 |
-
dropdown_config_path = path + "/assets/dropdowns/dropdown_config.json"
|
13 |
-
dropdown_config = load_config(dropdown_config_path)
|
14 |
-
return dropdown_config
|
15 |
|
16 |
#--------------------------------------------------------- LEVEL 1 DROPDOWNS
|
17 |
def retrieve_config_options(label):
|
18 |
-
dropdown_config = get_custom_config_dropdowns()
|
19 |
options = list(dropdown_config[label].keys())
|
20 |
options = [option.title() for option in options]
|
21 |
return options
|
@@ -56,7 +45,7 @@ def get_options(value):
|
|
56 |
open_field = None
|
57 |
extras = None
|
58 |
extras_label = None
|
59 |
-
dropdown_config = get_custom_config_dropdowns()
|
60 |
for _, sub_dict in dropdown_config.items():
|
61 |
nested_dict = sub_dict.get(value)
|
62 |
if nested_dict is not None:
|
|
|
1 |
import gradio as gr
|
2 |
+
from config_utils import get_custom_config_dropdowns
|
|
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
#--------------------------------------------------------- LEVEL 1 DROPDOWNS
|
6 |
def retrieve_config_options(label):
|
7 |
+
dropdown_config = get_custom_config_dropdowns("/assets/dropdowns/dropdown_config.json")
|
8 |
options = list(dropdown_config[label].keys())
|
9 |
options = [option.title() for option in options]
|
10 |
return options
|
|
|
45 |
open_field = None
|
46 |
extras = None
|
47 |
extras_label = None
|
48 |
+
dropdown_config = get_custom_config_dropdowns("/assets/dropdowns/dropdown_config.json")
|
49 |
for _, sub_dict in dropdown_config.items():
|
50 |
nested_dict = sub_dict.get(value)
|
51 |
if nested_dict is not None:
|
app/followup_events.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from config_utils import get_custom_config_dropdowns
|
3 |
+
|
4 |
+
def create_followup_section():
|
5 |
+
followup_config = get_custom_config_dropdowns("/assets/dropdowns/followup_config.json")
|
6 |
+
followup_config = followup_config["Event follow-up"]
|
7 |
+
with gr.Row():
|
8 |
+
for key, val in followup_config.items():
|
9 |
+
followup_label = key
|
10 |
+
if "Options" in val.keys():
|
11 |
+
gr.Dropdown(choices=val["Options"], label=followup_label, visible=True)
|
12 |
+
with gr.Row():
|
13 |
+
for key, val in followup_config.items():
|
14 |
+
followup_label = key
|
15 |
+
if "Open" in val.keys():
|
16 |
+
gr.Textbox(label=followup_label, visible=True)
|
app/main.py
CHANGED
@@ -97,6 +97,9 @@ with gr.Blocks() as demo:
|
|
97 |
|
98 |
dropdown_wounded.select(on_select, None, [dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
|
99 |
|
|
|
|
|
|
|
100 |
# ---------------------------------------------------------
|
101 |
#Submit Button
|
102 |
with gr.Column(scale=1):
|
|
|
97 |
|
98 |
dropdown_wounded.select(on_select, None, [dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded])
|
99 |
|
100 |
+
# ---------------------------------------------------------
|
101 |
+
#Follow up Events
|
102 |
+
|
103 |
# ---------------------------------------------------------
|
104 |
#Submit Button
|
105 |
with gr.Column(scale=1):
|
app/top_section.py
CHANGED
@@ -23,7 +23,6 @@ def create_top_section(visible):
|
|
23 |
return image_row, button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause
|
24 |
|
25 |
def create_dropdown(visible):
|
26 |
-
print(visible)
|
27 |
with gr.Row() as dropdown_row:
|
28 |
dropdown = gr.Dropdown(choices=[], label="Dropdown", interactive=True, visible=visible)
|
29 |
openfield_level2 = gr.Textbox(visible=False)
|
|
|
23 |
return image_row, button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause
|
24 |
|
25 |
def create_dropdown(visible):
|
|
|
26 |
with gr.Row() as dropdown_row:
|
27 |
dropdown = gr.Dropdown(choices=[], label="Dropdown", interactive=True, visible=visible)
|
28 |
openfield_level2 = gr.Textbox(visible=False)
|
app/wounded.py
CHANGED
@@ -1,14 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
from top_section import create_top_section, create_dropdown
|
|
|
3 |
|
4 |
def show_section_wounded(visible):
|
5 |
-
#with gr.Tab("Wounded Information"):
|
6 |
with gr.Column(visible=visible) as wounded_section:
|
7 |
gr.Markdown("# Wounded Animal")
|
8 |
-
gr.Markdown("Please describe the wound's cause.")
|
9 |
|
10 |
image_row, button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause = create_top_section(visible)
|
11 |
dropdown_row, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_dropdown(visible)
|
12 |
|
|
|
|
|
|
|
13 |
# Change variables and names
|
14 |
return wounded_section, button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2
|
|
|
1 |
import gradio as gr
|
2 |
from top_section import create_top_section, create_dropdown
|
3 |
+
from followup_events import create_followup_section
|
4 |
|
5 |
def show_section_wounded(visible):
|
|
|
6 |
with gr.Column(visible=visible) as wounded_section:
|
7 |
gr.Markdown("# Wounded Animal")
|
8 |
+
gr.Markdown("## Please describe the wound's cause.")
|
9 |
|
10 |
image_row, button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause = create_top_section(visible)
|
11 |
dropdown_row, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_dropdown(visible)
|
12 |
|
13 |
+
gr.Markdown("## Follow-up Events")
|
14 |
+
create_followup_section()
|
15 |
+
|
16 |
# Change variables and names
|
17 |
return wounded_section, button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2
|