chore: format code and update readme
Browse filesFiles changed (46)
- .github/workflows/sync_dataset_hf.yml+2-2
- .gitignore+2-2
- .pre-commit-config.yaml+1-1
- Dockerfile+2-2
- README.md+19-21
- app/.env.dist+2-1
- app/about.py+29-20
- app/assets/config/config_checkbox_behavior.json+2-2
- app/assets/config/config_checkbox_behavior_simple.json+2-2
- app/assets/config/config_checkbox_physical.json+2-2
- app/assets/config/config_checkbox_physical_simple.json+2-2
- app/assets/config/config_dropdown_circumstances.json+27-27
- app/assets/config/config_followup.json+2-2
- app/behavior/class_behavior.py+36-15
- app/circumstances/circumstances.py+99-42
- app/circumstances/class_circumstance.py+186-73
- app/contacts.py+56-41
- app/dead_wounded/dead.py+86-27
- app/dead_wounded/wounded.py+104-36
- app/follow_up/class_follow_up.py+28-20
- app/follow_up/followup_events.py+63-24
- app/geolocalisation/class_geolocalisation.py+5-3
- app/geolocalisation/js_geolocation.py+9-7
- app/geolocalisation/maps.py+27-19
- app/main.py+8-5
- app/mode_advanced.py+854-300
- app/mode_simple.py+829-286
- app/physical/class_physical.py+38-48
- app/physical/class_physical_simple.py+19-32
- app/physical/physical_boxes_define.py+10-10
- app/physical/physical_boxes_map.py+10-8
- app/physical/physical_checkbox.py-1
- app/physical/physical_select_animal.py+48-18
- app/styling/style.py+6-4
- app/styling/theme.py+15-15
- app/sync_dataset_hf.py+11-15
- app/utils/utils_checkbox.py+25-15
- app/utils/utils_config.py+4-3
- app/utils/utils_visible.py+3-3
- app/validation_submission/processing.py+43-25
- app/validation_submission/resets.py+7-2
- app/validation_submission/submission.py+4-2
- app/validation_submission/utils_individual.py+4-5
- app/validation_submission/utils_save.py+6-4
- app/validation_submission/validation.py+31-14
- requirements.txt+1-1
9 unmodified lines101112131415167 unmodified lines242526279 unmodified linessteps:- name: Checkout repositoryuses: actions/checkout@v2- name: Set up Pythonuses: actions/setup-python@v2with:7 unmodified lines- name: Sync Datasetsenv:HF_TOKEN: ${{ secrets.HF_TOKEN }}run: python app/sync_dataset_hf.py9 unmodified lines101112131415167 unmodified lines242526279 unmodified linessteps:- name: Checkout repositoryuses: actions/checkout@v2- name: Set up Pythonuses: actions/setup-python@v2with:7 unmodified lines- name: Sync Datasetsenv:HF_TOKEN: ${{ secrets.HF_TOKEN }}run: python app/sync_dataset_hf.py
4 unmodified lines5678910111213144 unmodified lines*.py[cod]*$py.class#Datatest/data/*.jsondata/*.jsonapp/assets/tmp_json/*.json# C extensions*.so4 unmodified lines5678910111213144 unmodified lines*.py[cod]*$py.class#Datatest/data/*.jsondata/*.jsonapp/assets/tmp_json/*.json# C extensions*.so
17 unmodified lines1819202117 unmodified linesargs: [ --exit-zero ]verbose: true- id: ruff-formattypes_or: [ python, pyi, jupyter ]17 unmodified lines1819202117 unmodified linesargs: [ --exit-zero ]verbose: true- id: ruff-formattypes_or: [ python, pyi, jupyter ]
5 unmodified lines678910111212 unmodified lines252627282930315 unmodified lines# RUN apt update# RUN apt-get update# RUN apt install python3.10 python3-pip -y# https://stackoverflow.com/questions/75608323/how-do-i-solve-error-externally-managed-environment-every-time-i-use-pip-3# https://veronneau.org/python-311-pip-and-breaking-system-packages.html12 unmodified lines&& apt-get install -y --no-install-recommends \unzip \nano \git \g++ \gcc \htop \5 unmodified lines678910111212 unmodified lines252627282930315 unmodified lines# RUN apt update# RUN apt-get update# RUN apt install python3.10 python3-pip -y# https://stackoverflow.com/questions/75608323/how-do-i-solve-error-externally-managed-environment-every-time-i-use-pip-3# https://veronneau.org/python-311-pip-and-breaking-system-packages.html12 unmodified lines&& apt-get install -y --no-install-recommends \unzip \nano \git \g++ \gcc \htop \
7 unmodified lines89101112131415161718192021223 unmodified lines26272829303132333435363738394041424344454647484950517 unmodified linesshort_description: Digiwild---# digiwild## Docker``` bashdocker build -t ordes/digiwild .`````` bashdocker run -it -p 7860:7860 ordes/digiwild```3 unmodified linespython3 main.py```### How to develop on docker``` bashdocker run -it -p 7860:7860 -v $(pwd):/home/user/digiwild/ --entrypoint bash ordes/digiwild```## TODO- [x] Change `wounded` to `wounded / sick`- [x] Info formatting- [x] Use in memory object instead of files to avoid writting / reading problems.- [ ] Connection to a database? Maybe an open MongoDB- [x] GPS Compatibility- [x] New fields suggested: Number individuals, Species, Comments- [ ] Add info and placeholder information to the different components.## Needs- Camera with multiples pictures?- Uploading of pics- GPS location- Comments- Symptomps selection (Dropdown)7 unmodified lines89101112131415161718192021222324252627282930313233343536373 unmodified lines4142434445464748497 unmodified linesshort_description: Digiwild---# Digiwild# Wilf Life monitoring - Bird Monitoring Use-Case## AboutThis work stemmed from a fruitful collaboration between [Swiss Data Science Center](https://www.datascience.ch) and [Institute for Fish and Wildlife Health, University of Bern](https://www.fiwi.vetsuisse.unibe.ch).The resulting [Gradio App is available to use on Hugging Face](https://huggingface.co/spaces/SDSC/digiwild), which is coupled to the [digiwild Hugging Face Dataset](https://huggingface.co/datasets/SDSC/digiwild-dataset).Credits and special thanks for the project can be found in the `About` section of the app.## How to Contact Us?For **code contribution and any technical issues**, please open an `Issue` on this repository, we will address it as soon as possible. For enhancing the app, please open a PR, we welcome any and all enhancements or fixes.For **usage of the app and any monitoring related questions**, please reach out to FIWI via [their contacts](https://www.fiwi.vetsuisse.unibe.ch/about_us/team/index_eng.html).## Development and Local set-up### Docker``` bashdocker build -t ordes/digiwild .`````` bashdocker run -it -p 7860:7860 ordes/digiwild```3 unmodified linespython3 main.py```How to develop on docker:``` bashdocker run -it -p 7860:7860 -v $(pwd):/home/user/digiwild/ --entrypoint bash ordes/digiwild```
1PATH_ASSETS="YOUR_PATH_HERE"12PATH_ASSETS="YOUR_PATH_HERE"HF_TOKEN="hf_YOUR_TOKEN"
1 unmodified line234567891011121314151617186 unmodified lines25262728293031323334354 unmodified lines4041424344454634 unmodified lines8182838485868788899091929394959697981 unmodified linefrom dotenv import load_dotenvimport osload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv('PATH_ASSETS')PATH_ICONS = PATH + PATH_ASSETS + "icons/"credits_text = """# CreditsThis work stemmed from a fruitful collaboration between SDSC and FIWI.## Scientific Expertise : FIWI from UniBEFrom the [Institute for Fish and Wildlife Health, University of Bern](https://www.fiwi.vetsuisse.unibe.ch)- **Isabelle Wethli**6 unmodified lines- **Carlos Viviar Rios**- **Laure Vancauwenberghe**## How to Contact Us?Please reach out to FIWI via [their contacts](https://www.fiwi.vetsuisse.unibe.ch/about_us/team/index_eng.html).## Special Thanks- **Vogelwarte** for their advice, especially Samuel Wechsler.- **Biolovision SA**, providers of **ornitho.ch**, for their collaboration: circumstances are matched to their current data collection schema on ornitho.ch4 unmodified lines### Icons' Attributions(scroll to see all)Biolovision for the circumstances icons.flying-doves-group: <a href="https://www.flaticon.com/free-icons/animal" title="animal icons">Animal icons created by Freepik - Flaticon</a>34 unmodified linesquestion: <a href="https://www.flaticon.com/free-icons/question" title="question icons">Question icons created by Freepik - Flaticon</a>"""with gr.Blocks(theme='shivi/calm_seafoam') as about:with gr.Row(scale = 1):gr.Image(PATH_ICONS+"sdsc.png",height=200,interactive=False,show_fullscreen_button = False, show_share_button=False,show_download_button=False, show_label=False)gr.Image(PATH_ICONS+"fiwi.png",height=200,interactive=False,show_fullscreen_button = False, show_share_button=False,show_download_button=False, show_label=False)gr.Markdown(credits_text, show_label=False)gr.Markdown(icons_text, show_label=False, height=100)1 unmodified line23456789101112131415161718196 unmodified lines26272829303132333435364 unmodified lines4142434445464734 unmodified lines8283848586878889909192939495969798991001011021031041051061071 unmodified linefrom dotenv import load_dotenvimport osload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv("PATH_ASSETS")PATH_ICONS = PATH + PATH_ASSETS + "icons/"credits_text = """# CreditsThis work stemmed from a fruitful collaboration between SDSC and FIWI.## Scientific Expertise : FIWI from UniBEFrom the [Institute for Fish and Wildlife Health, University of Bern](https://www.fiwi.vetsuisse.unibe.ch)- **Isabelle Wethli**6 unmodified lines- **Carlos Viviar Rios**- **Laure Vancauwenberghe**## How to Contact Us?Please reach out to FIWI via [their contacts](https://www.fiwi.vetsuisse.unibe.ch/about_us/team/index_eng.html).## Special Thanks- **Vogelwarte** for their advice, especially Samuel Wechsler.- **Biolovision SA**, providers of **ornitho.ch**, for their collaboration: circumstances are matched to their current data collection schema on ornitho.ch4 unmodified lines### Icons' Attributions(scroll to see all)Biolovision for the circumstances icons.flying-doves-group: <a href="https://www.flaticon.com/free-icons/animal" title="animal icons">Animal icons created by Freepik - Flaticon</a>34 unmodified linesquestion: <a href="https://www.flaticon.com/free-icons/question" title="question icons">Question icons created by Freepik - Flaticon</a>"""with gr.Blocks(theme="shivi/calm_seafoam") as about:with gr.Row(scale=1):gr.Image(PATH_ICONS + "sdsc.png",height=200,interactive=False,show_fullscreen_button=False,show_share_button=False,show_download_button=False,show_label=False,)gr.Image(PATH_ICONS + "fiwi.png",height=200,interactive=False,show_fullscreen_button=False,show_share_button=False,show_download_button=False,show_label=False,)gr.Markdown(credits_text, show_label=False)gr.Markdown(icons_text, show_label=False, height=100)
34 unmodified lines353637383940414234 unmodified lines{"Description": "Non responsive, does not fly away when approached, lethargy"},"No changes":{"Description": "Animal is acting normally"}}34 unmodified lines353637383940414234 unmodified lines{"Description": "Non responsive, does not fly away when approached, lethargy"},"No changes":{"Description": "Animal is acting normally"}}
10 unmodified lines111213141516171810 unmodified lines{"Description": "Circling, incoordination, tremors, convulsions"},"No changes":{"Description": "Animal is acting normally"}}10 unmodified lines111213141516171810 unmodified lines{"Description": "Circling, incoordination, tremors, convulsions"},"No changes":{"Description": "Animal is acting normally"}}
26 unmodified lines2728293031323315 unmodified lines4950515253545526 unmodified lines"Description": "Unusual beak growth"}},"Body":{"Emaciation": {"Description": "Breast muscles are not well developed"},15 unmodified lines"Missing limb": {"Description": "Missing limb"}},"Head incl. eyes":{"Ear changes": {"Description": "Swollen, crusts, plugged, discharge"},26 unmodified lines2728293031323315 unmodified lines4950515253545526 unmodified lines"Description": "Unusual beak growth"}},"Body":{"Emaciation": {"Description": "Breast muscles are not well developed"},15 unmodified lines"Missing limb": {"Description": "Missing limb"}},"Head incl. eyes":{"Ear changes": {"Description": "Swollen, crusts, plugged, discharge"},
11 unmodified lines121314151617181920212223242511 unmodified lines"Description": "Material (food, saliva) around/ in the beak, discharge from ears/ eyes/ beak/ nose"}},"Body":{},"Feathers/Wings/Tail":{"Feathers and skin change": {"Description": "Blackened/ burnt skin or feathers, deformed feathers, ear changes (swollen, crusts, plugged, discharge), discolored/ missing/ broken/ stained feathers, fluffed up plumage, warts/ crusts/ tumor-like growth, parasites"}},"Head incl. eyes":{"Eye changes": {"Description": "Swollen, reddened, closed, discharge, crusts"}11 unmodified lines121314151617181920212223242511 unmodified lines"Description": "Material (food, saliva) around/ in the beak, discharge from ears/ eyes/ beak/ nose"}},"Body":{},"Feathers/Wings/Tail":{"Feathers and skin change": {"Description": "Blackened/ burnt skin or feathers, deformed feathers, ear changes (swollen, crusts, plugged, discharge), discolored/ missing/ broken/ stained feathers, fluffed up plumage, warts/ crusts/ tumor-like growth, parasites"}},"Head incl. eyes":{"Eye changes": {"Description": "Swollen, reddened, closed, discharge, crusts"}
12345678910111213142 unmodified lines171819202122232425262728293031323334353637383940414243444546474849504 unmodified lines555657585960613 unmodified lines65666768697071727374757677787980818283848586878889909192939495969798991 unmodified line1011021031041051061071081091101111121131141151161171181191201211222 unmodified lines125126127128129130131{"Collision with a means of transport":{"road vehicle":{"Options": {"road_type" : ["highway", "main road", "secondary road", "local road/path/trail", "parking lot", "other road", "unknown road"]},"Open": "Infrastructure_number"},"train":{"Open": "Infrastructure_number"},2 unmodified lines"other transport collision": {},"unknown": {}},"Destruction / Deliberatly removed" :{"hunting":{"Options": {"method" : ["shooting", "bow", "falconry","hounds hunting", "digging up", "other hunting", "unknow hunting"]}},"trap":{"Options": {"method": ["killing trap", "pole trap","trap cage", "corvids nasse", "net", "cage trap","fall-trap", "glue trap", "insect trap", "other trap", "unknown trap"]}},"poisoning": {},"removal or direct capture":{"Options": {"method": ["gassing", "raptor captured at nest","brood destruction", "traffic/trade", "capture accident","scientific sample", "other removal", "unknown removal"]}},"fishing":{"Options": {"method" : ["drowned/tangled", "beached with capture indications","other fishing", "unknown fishing"]}},4 unmodified lines{"pylone and electric grid":{"Options": {"infrastructure" : ["electric line", "pole/pylon", "other structure", "unknown structure"]},3 unmodified lines}},"windfarm": {},"other collision":{"Options": {"object": ["window", "building", "lighthouse", "cable", "wire fence/barbed wire", "other crash", "unknown crash"]}},"fall":{"Options": {"location": ["chimney", "empty pole", "hole/well", "other fall", "unknown fall"]}},"development work":{"Options": {"work_type" : ["transport infrastructure", "building", "other work", "unknown work"]}},"pollution / contamination":{"Options": {"pollution_type" : ["oil pollution", "chemical pollution", "heavy metals","light", "noise", "plastic ingestion", "other pollution", "unknown pollution"]},"agricultural net protection": {},"vegetal / forest work":{"Options": {"work_type" : ["clearing/mowing/plowing", "tree felling/pruning","other forest work", "unknown forest work"]}}1 unmodified line"other indirect destruction": {},"unknown": {}},"Natural cause":{"predation":{"Options": {"predator" : ["cat", "dog", "rooster/hen", "other domestic animal", "wild birds","wild mammal", "other predator", "unknown predator"]}},"weather":{"Options": {"condition" : ["cold wave", "drought", "hail", "lightening", "storm", "other weather", "unknown weather"]}},"natural disaster":{"Options": {"disaster" : ["fire", "avalanche", "rock fall", "mudslide", "volcanic eruption/ashes", "other natural disaster", "unknown natural disaster"]2 unmodified lines"nest fall": {},"stranding due to exhaustion": {},"disease/parasite": {},"accidental drowing":{"Options": {"drowning_location" : ["drinking trough", "pool", "storm pool", "irrigation pool", "natural pool", "flood", "other location", "unknown location"]12345678910111213142 unmodified lines171819202122232425262728293031323334353637383940414243444546474849504 unmodified lines555657585960613 unmodified lines65666768697071727374757677787980818283848586878889909192939495969798991 unmodified line1011021031041051061071081091101111121131141151161171181191201211222 unmodified lines125126127128129130131{"Collision with a means of transport":{"road vehicle":{"Options": {"road_type" : ["highway", "main road", "secondary road", "local road/path/trail", "parking lot", "other road", "unknown road"]},"Open": "Infrastructure_number"},"train":{"Open": "Infrastructure_number"},2 unmodified lines"other transport collision": {},"unknown": {}},"Destruction / Deliberatly removed" :{"hunting":{"Options": {"method" : ["shooting", "bow", "falconry","hounds hunting", "digging up", "other hunting", "unknow hunting"]}},"trap":{"Options": {"method": ["killing trap", "pole trap","trap cage", "corvids nasse", "net", "cage trap","fall-trap", "glue trap", "insect trap", "other trap", "unknown trap"]}},"poisoning": {},"removal or direct capture":{"Options": {"method": ["gassing", "raptor captured at nest","brood destruction", "traffic/trade", "capture accident","scientific sample", "other removal", "unknown removal"]}},"fishing":{"Options": {"method" : ["drowned/tangled", "beached with capture indications","other fishing", "unknown fishing"]}},4 unmodified lines{"pylone and electric grid":{"Options": {"infrastructure" : ["electric line", "pole/pylon", "other structure", "unknown structure"]},3 unmodified lines}},"windfarm": {},"other collision":{"Options": {"object": ["window", "building", "lighthouse", "cable", "wire fence/barbed wire", "other crash", "unknown crash"]}},"fall":{"Options": {"location": ["chimney", "empty pole", "hole/well", "other fall", "unknown fall"]}},"development work":{"Options": {"work_type" : ["transport infrastructure", "building", "other work", "unknown work"]}},"pollution / contamination":{"Options": {"pollution_type" : ["oil pollution", "chemical pollution", "heavy metals","light", "noise", "plastic ingestion", "other pollution", "unknown pollution"]},"agricultural net protection": {},"vegetal / forest work":{"Options": {"work_type" : ["clearing/mowing/plowing", "tree felling/pruning","other forest work", "unknown forest work"]}}1 unmodified line"other indirect destruction": {},"unknown": {}},"Natural cause":{"predation":{"Options": {"predator" : ["cat", "dog", "rooster/hen", "other domestic animal", "wild birds","wild mammal", "other predator", "unknown predator"]}},"weather":{"Options": {"condition" : ["cold wave", "drought", "hail", "lightening", "storm", "other weather", "unknown weather"]}},"natural disaster":{"Options": {"disaster" : ["fire", "avalanche", "rock fall", "mudslide", "volcanic eruption/ashes", "other natural disaster", "unknown natural disaster"]2 unmodified lines"nest fall": {},"stranding due to exhaustion": {},"disease/parasite": {},"accidental drowing":{"Options": {"drowning_location" : ["drinking trough", "pool", "storm pool", "irrigation pool", "natural pool", "flood", "other location", "unknown location"]
1234514 unmodified lines20212223{"Event follow-up":{"Animal collected": {"Options": ["Yes", "No"]14 unmodified lines"Open": {}}}}1234514 unmodified lines20212223{"Event follow-up":{"Animal collected": {"Options": ["Yes", "No"]14 unmodified lines"Open": {}}}}
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515 unmodified lines575859606162636465from pydantic import BaseModel, Fieldfrom typing import Literal, List, Union, Optionalclass Behavior(BaseModel):type: strdescription: Optional[str] = None # Making the description field optional# --- Specific Behavior classes ---class AbnormalBreathing(Behavior):type: Literal['abnormal breathing']description: Optional[Literal["Problems breathing, breathing sounds"]] = Noneclass CrashFalling(Behavior):type: Literal['crash, falling from the sky']description: Optional[Literal["Suddenly falling from the sky"]] = Noneclass Diarrhea(Behavior):type: Literal['diarrhea']description: Optional[Literal["Observed diarrhea"]] = Noneclass Lameness(Behavior):type: Literal['lameness']description: Optional[Literal["Apparent limping or not able to walk properly"]] = Noneclass Neurological(Behavior):type: Literal['neurological']description: Optional[Literal["Circling, incoordination, tremors, convulsions, fast eye movements"]] = Noneclass OtherAbnormalBehavior(Behavior):type: Literal['other abnormal behavior']description: Optional[Literal["Other than weakness, other than neurologic"]] = Noneclass UnableToFly(Behavior):type: Literal['unable to fly']description: Optional[Literal["Animal alert and tries to fly but can not take off"]] = Noneclass Vomiting(Behavior):type: Literal['vomiting']description: Optional[Literal["Throwing up undigested food, regurgitating"]] = Noneclass Weakness(Behavior):type: Literal['weakness']description: Optional[Literal["Non responsive, does not fly away when approached, lethargy"]] = Noneclass NoChanges(Behavior):type: Literal['no changes']description: Optional[Literal["Animal is acting normally"]] = None# Union of all possible behaviorsBehaviorType = Union[AbnormalBreathing,5 unmodified linesUnableToFly,Vomiting,Weakness,NoChanges]# Main class that logs multiple behaviorsclass Behaviors(BaseModel):behaviors_radio: str # e.g., "Yes"12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970715 unmodified lines77787980818283848586from pydantic import BaseModel, Fieldfrom typing import Literal, List, Union, Optionalclass Behavior(BaseModel):type: strdescription: Optional[str] = None # Making the description field optional# --- Specific Behavior classes ---class AbnormalBreathing(Behavior):type: Literal["abnormal breathing"]description: Optional[Literal["Problems breathing, breathing sounds"]] = Noneclass CrashFalling(Behavior):type: Literal["crash, falling from the sky"]description: Optional[Literal["Suddenly falling from the sky"]] = Noneclass Diarrhea(Behavior):type: Literal["diarrhea"]description: Optional[Literal["Observed diarrhea"]] = Noneclass Lameness(Behavior):type: Literal["lameness"]description: Optional[Literal["Apparent limping or not able to walk properly"]] = Noneclass Neurological(Behavior):type: Literal["neurological"]description: Optional[Literal["Circling, incoordination, tremors, convulsions, fast eye movements"]] = Noneclass OtherAbnormalBehavior(Behavior):type: Literal["other abnormal behavior"]description: Optional[Literal["Other than weakness, other than neurologic"]] = Noneclass UnableToFly(Behavior):type: Literal["unable to fly"]description: Optional[Literal["Animal alert and tries to fly but can not take off"]] = Noneclass Vomiting(Behavior):type: Literal["vomiting"]description: Optional[Literal["Throwing up undigested food, regurgitating"]] = Noneclass Weakness(Behavior):type: Literal["weakness"]description: Optional[Literal["Non responsive, does not fly away when approached, lethargy"]] = Noneclass NoChanges(Behavior):type: Literal["no changes"]description: Optional[Literal["Animal is acting normally"]] = None# Union of all possible behaviorsBehaviorType = Union[AbnormalBreathing,5 unmodified linesUnableToFly,Vomiting,Weakness,NoChanges,]# Main class that logs multiple behaviorsclass Behaviors(BaseModel):behaviors_radio: str # e.g., "Yes"
6 unmodified lines789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676 unmodified linesload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv('PATH_ASSETS')LOGO_PATH = PATH + PATH_ASSETS + "logos"CAUSE_COL_WIDTH = "50px"def show_circumstances(choice, individual):visible = set_visible(choice)individual = add_data_to_individual("circumstance_radio",choice, individual)button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_circumstances(visible)return button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2, individualdef create_circumstances(visible):button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause = create_circumstances_buttons(visible)dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_circumstances_dropdown(visible)return button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2def create_circumstances_buttons(visible):with gr.Row() as image_row:with gr.Column(scale=1, min_width=CAUSE_COL_WIDTH):button_collision = gr.Button("Collision with a means of transport",visible=visible,icon=LOGO_PATH + '/van.png',elem_id="buttons-conditions")with gr.Column(scale=1, min_width=CAUSE_COL_WIDTH):button_deliberate_destruction = gr.Button("Destruction / Deliberatly removed",icon=LOGO_PATH + '/destruction.png',visible=visible,elem_id="buttons-conditions")with gr.Column(scale=1, min_width=CAUSE_COL_WIDTH):button_indirect_destruction = gr.Button("Indirect destruction",icon=LOGO_PATH + '/indirect.png',visible=visible,elem_id="buttons-conditions")with gr.Column(scale=1, min_width=CAUSE_COL_WIDTH):button_natural_cause = gr.Button("Natural cause",icon=LOGO_PATH + '/natural.png',visible=visible,elem_id="buttons-conditions")return button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_causedef create_circumstances_dropdown(visible):with gr.Row() as dropdown_row:dropdown = gr.Dropdown(choices=[],label="Choices will appear here...",visible=visible, interactive=False, elem_id="dropdown-conditions")openfield_level2 = gr.Textbox(visible=False, elem_id="dropdown-conditions")dropdown_level2 = gr.Dropdown(choices=[], visible=False, elem_id="dropdown-conditions")dropdown_extra_level2 = gr.Dropdown(choices=[], visible=False, elem_id="dropdown-conditions")return dropdown, dropdown_level2, openfield_level2, dropdown_extra_level26 unmodified lines7891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231246 unmodified linesload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv("PATH_ASSETS")LOGO_PATH = PATH + PATH_ASSETS + "logos"CAUSE_COL_WIDTH = "50px"def show_circumstances(choice, individual):visible = set_visible(choice)individual = add_data_to_individual("circumstance_radio", choice, individual)(button_collision,button_deliberate_destruction,button_indirect_destruction,button_natural_cause,dropdown,dropdown_level2,openfield_level2,dropdown_extra_level2,) = create_circumstances(visible)return (button_collision,button_deliberate_destruction,button_indirect_destruction,button_natural_cause,dropdown,dropdown_level2,openfield_level2,dropdown_extra_level2,individual,)def create_circumstances(visible):(button_collision,button_deliberate_destruction,button_indirect_destruction,button_natural_cause,) = create_circumstances_buttons(visible)(dropdown,dropdown_level2,openfield_level2,dropdown_extra_level2,) = create_circumstances_dropdown(visible)return (button_collision,button_deliberate_destruction,button_indirect_destruction,button_natural_cause,dropdown,dropdown_level2,openfield_level2,dropdown_extra_level2,)def create_circumstances_buttons(visible):with gr.Row() as image_row:with gr.Column(scale=1, min_width=CAUSE_COL_WIDTH):button_collision = gr.Button("Collision with a means of transport",visible=visible,icon=LOGO_PATH + "/van.png",elem_id="buttons-conditions",)with gr.Column(scale=1, min_width=CAUSE_COL_WIDTH):button_deliberate_destruction = gr.Button("Destruction / Deliberatly removed",icon=LOGO_PATH + "/destruction.png",visible=visible,elem_id="buttons-conditions",)with gr.Column(scale=1, min_width=CAUSE_COL_WIDTH):button_indirect_destruction = gr.Button("Indirect destruction",icon=LOGO_PATH + "/indirect.png",visible=visible,elem_id="buttons-conditions",)with gr.Column(scale=1, min_width=CAUSE_COL_WIDTH):button_natural_cause = gr.Button("Natural cause",icon=LOGO_PATH + "/natural.png",visible=visible,elem_id="buttons-conditions",)return (button_collision,button_deliberate_destruction,button_indirect_destruction,button_natural_cause,)def create_circumstances_dropdown(visible):with gr.Row() as dropdown_row:dropdown = gr.Dropdown(choices=[],label="Choices will appear here...",visible=visible,interactive=False,elem_id="dropdown-conditions",)openfield_level2 = gr.Textbox(visible=False, elem_id="dropdown-conditions")dropdown_level2 = gr.Dropdown(choices=[], visible=False, elem_id="dropdown-conditions")dropdown_extra_level2 = gr.Dropdown(choices=[], visible=False, elem_id="dropdown-conditions")return dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115229 unmodified lines1821831841851861871881891901911921931941956 unmodified lines202203204205from pydantic import BaseModel, Fieldfrom typing import Literal, List, Union, Optional# Base class for CircumstanceType with a discriminator field 'type'class CircumstanceTypeBase(BaseModel):type: str# Collision with means of transportclass RoadVehicleCollision(CircumstanceTypeBase):type: Literal['road_vehicle']infrastructure_number: Optional[str] = Noneroad_type: Literal['highway', 'main road','secondary road', 'local road/path/trail','parking lot']class TrainCollision(CircumstanceTypeBase):type: Literal['train']infrastructure_number: strclass AircraftCollision(CircumstanceTypeBase):type: Literal['aircraft']class BoatCollision(CircumstanceTypeBase):type: Literal['boat']class OtherTransportCollision(CircumstanceTypeBase):type: Literal['other transport collision']class UnknownTransportCollision(CircumstanceTypeBase):type: Literal['unknown transport collision']# Destruction / Deliberately removedclass HuntingDestruction(CircumstanceTypeBase):type: Literal['hunting']method: Literal['shooting', 'bow', 'falconry','hounds hunting', 'digging up',"other hunting", "unknow hunting"]class TrapDestruction(CircumstanceTypeBase):type: Literal['trap']method: Literal['killing trap', 'pole trap', 'trap cage', 'corvids nasse','net', 'cage trap', 'fall-trap', 'glue trap', 'insect trap',"other trap", "unknown trap"]class PoisoningDestruction(CircumstanceTypeBase):type: Literal['poisoning']class RemovalDestruction(CircumstanceTypeBase):type: Literal['removal or direct capture']method: Literal['gassing', 'raptor captured at nest', 'brood destruction','traffic/trade', 'capture accident', 'scientific sample',"other removal", "unknown removal"]class FishingDestruction(CircumstanceTypeBase):type: Literal['fishing']method: Literal['drowned/tangled', 'beached with capture indications', "other fishing", "unknown fishing"]class OtherDestruction(CircumstanceTypeBase):type: Literal['other destruction']class UnknownDestruction(CircumstanceTypeBase):type: Literal['unknown destruction']# Indirect destructionclass PylonElectricGridDestruction(CircumstanceTypeBase):type: Literal['pylone and electric grid']infrastructure: Literal['electric line', 'pole/pylon', "other structure", "unknown structure"]cause: Literal['collision', 'electrocution']class WindfarmDestruction(CircumstanceTypeBase):type: Literal['windfarm']class OtherCollisionDestruction(CircumstanceTypeBase):type: Literal['other collision']object: Literal['window', 'building', 'lighthouse','cable', 'wire fence/barbed wire', 'other crash', 'unknown crash']class FallDestruction(CircumstanceTypeBase):type: Literal['fall']location: Literal['chimney', 'empty pole', 'hole/well', 'other fall', 'unknown fall']class DevelopmentWorkDestruction(CircumstanceTypeBase):type: Literal['development work']work_type: Literal['transport infrastructure', 'building', 'other work', 'unknown work']class PollutionContaminationDestruction(CircumstanceTypeBase):type: Literal['pollution / contamination']pollution_type: Literal['oil pollution', 'chemical pollution', 'heavy metals','light', 'noise','plastic ingestion', 'other pollution', 'unknown pollution']class AgriculturalNetProtectionDestruction(CircumstanceTypeBase):type: Literal['agricultural net protection']class VegetalForestWorkDestruction(CircumstanceTypeBase):type: Literal['vegetal / forest work']work_type: Literal['clearing/mowing/plowing', 'tree felling/pruning','other forest work', 'unknown forest work']class OtherIndirectDestruction(CircumstanceTypeBase):type: Literal['other indirect destruction']class UnknownIndirectDestruction(CircumstanceTypeBase):type: Literal['unknown indirect destruction']# Natural causeclass Predation(CircumstanceTypeBase):type: Literal['predation']predator: Literal['cat', 'dog', 'rooster/hen','other domestic animal', 'wild birds','wild mammal', 'other predator', 'unknown predator']class Weather(CircumstanceTypeBase):type: Literal['weather']condition: Literal['cold wave', 'drought', 'hail','lightening', 'storm','other weather', 'unknown weather']class NaturalDisaster(CircumstanceTypeBase):type: Literal['natural disaster']disaster: Literal['fire', 'avalanche', 'rock fall','mudslide', 'volcanic eruption/ashes','other natural disaster', 'unknown natural disaster']class NestFall(CircumstanceTypeBase):type: Literal['nest fall']class StrandingExhaustion(CircumstanceTypeBase):type: Literal['stranding due to exhaustion']class DiseaseParasite(CircumstanceTypeBase):type: Literal['disease/parasite']class AccidentalDrowning(CircumstanceTypeBase):type: Literal['accidental drowning']drowning_location: Literal['drinking trough', 'pool','storm pool', 'irrigation pool','natural pool', 'flood','other location', 'unknown location']class OtherNaturalCause(CircumstanceTypeBase):type: Literal['other natural cause']class UnknownNaturalCause(CircumstanceTypeBase):type: Literal['unknown natural cause']# Unknown causeclass UnknownCircumstance(CircumstanceTypeBase):type: Literal['unknown']# Union of all possible CircumstanceTypes with 'type' as the discriminatorCircumstanceType = Union[29 unmodified linesAccidentalDrowning,OtherNaturalCause,UnknownNaturalCause,UnknownCircumstance]# Main Circumstance classclass Circumstances(BaseModel):circumstance_radio: str # e.g., "Yes"circumstance: Optional[str] = None # e.g., "COLLISION"circumstance_type: Optional[CircumstanceType] = Field(None, discriminator='type')# Example usage6 unmodified lines# }# }# circumstance_instance = Circumstance(**json_data)# circumstance_schema = Circumstance.schema_json(indent=2)12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326429 unmodified lines2942952962972982993003013023033043053063073086 unmodified lines315316317318from pydantic import BaseModel, Fieldfrom typing import Literal, List, Union, Optional# Base class for CircumstanceType with a discriminator field 'type'class CircumstanceTypeBase(BaseModel):type: str# Collision with means of transportclass RoadVehicleCollision(CircumstanceTypeBase):type: Literal["road_vehicle"]infrastructure_number: Optional[str] = Noneroad_type: Literal["highway", "main road", "secondary road", "local road/path/trail", "parking lot"]class TrainCollision(CircumstanceTypeBase):type: Literal["train"]infrastructure_number: strclass AircraftCollision(CircumstanceTypeBase):type: Literal["aircraft"]class BoatCollision(CircumstanceTypeBase):type: Literal["boat"]class OtherTransportCollision(CircumstanceTypeBase):type: Literal["other transport collision"]class UnknownTransportCollision(CircumstanceTypeBase):type: Literal["unknown transport collision"]# Destruction / Deliberately removedclass HuntingDestruction(CircumstanceTypeBase):type: Literal["hunting"]method: Literal["shooting","bow","falconry","hounds hunting","digging up","other hunting","unknow hunting",]class TrapDestruction(CircumstanceTypeBase):type: Literal["trap"]method: Literal["killing trap","pole trap","trap cage","corvids nasse","net","cage trap","fall-trap","glue trap","insect trap","other trap","unknown trap",]class PoisoningDestruction(CircumstanceTypeBase):type: Literal["poisoning"]class RemovalDestruction(CircumstanceTypeBase):type: Literal["removal or direct capture"]method: Literal["gassing","raptor captured at nest","brood destruction","traffic/trade","capture accident","scientific sample","other removal","unknown removal",]class FishingDestruction(CircumstanceTypeBase):type: Literal["fishing"]method: Literal["drowned/tangled","beached with capture indications","other fishing","unknown fishing",]class OtherDestruction(CircumstanceTypeBase):type: Literal["other destruction"]class UnknownDestruction(CircumstanceTypeBase):type: Literal["unknown destruction"]# Indirect destructionclass PylonElectricGridDestruction(CircumstanceTypeBase):type: Literal["pylone and electric grid"]infrastructure: Literal["electric line", "pole/pylon", "other structure", "unknown structure"]cause: Literal["collision", "electrocution"]class WindfarmDestruction(CircumstanceTypeBase):type: Literal["windfarm"]class OtherCollisionDestruction(CircumstanceTypeBase):type: Literal["other collision"]object: Literal["window","building","lighthouse","cable","wire fence/barbed wire","other crash","unknown crash",]class FallDestruction(CircumstanceTypeBase):type: Literal["fall"]location: Literal["chimney", "empty pole", "hole/well", "other fall", "unknown fall"]class DevelopmentWorkDestruction(CircumstanceTypeBase):type: Literal["development work"]work_type: Literal["transport infrastructure", "building", "other work", "unknown work"]class PollutionContaminationDestruction(CircumstanceTypeBase):type: Literal["pollution / contamination"]pollution_type: Literal["oil pollution","chemical pollution","heavy metals","light","noise","plastic ingestion","other pollution","unknown pollution",]class AgriculturalNetProtectionDestruction(CircumstanceTypeBase):type: Literal["agricultural net protection"]class VegetalForestWorkDestruction(CircumstanceTypeBase):type: Literal["vegetal / forest work"]work_type: Literal["clearing/mowing/plowing","tree felling/pruning","other forest work","unknown forest work",]class OtherIndirectDestruction(CircumstanceTypeBase):type: Literal["other indirect destruction"]class UnknownIndirectDestruction(CircumstanceTypeBase):type: Literal["unknown indirect destruction"]# Natural causeclass Predation(CircumstanceTypeBase):type: Literal["predation"]predator: Literal["cat","dog","rooster/hen","other domestic animal","wild birds","wild mammal","other predator","unknown predator",]class Weather(CircumstanceTypeBase):type: Literal["weather"]condition: Literal["cold wave","drought","hail","lightening","storm","other weather","unknown weather",]class NaturalDisaster(CircumstanceTypeBase):type: Literal["natural disaster"]disaster: Literal["fire","avalanche","rock fall","mudslide","volcanic eruption/ashes","other natural disaster","unknown natural disaster",]class NestFall(CircumstanceTypeBase):type: Literal["nest fall"]class StrandingExhaustion(CircumstanceTypeBase):type: Literal["stranding due to exhaustion"]class DiseaseParasite(CircumstanceTypeBase):type: Literal["disease/parasite"]class AccidentalDrowning(CircumstanceTypeBase):type: Literal["accidental drowning"]drowning_location: Literal["drinking trough","pool","storm pool","irrigation pool","natural pool","flood","other location","unknown location",]class OtherNaturalCause(CircumstanceTypeBase):type: Literal["other natural cause"]class UnknownNaturalCause(CircumstanceTypeBase):type: Literal["unknown natural cause"]# Unknown causeclass UnknownCircumstance(CircumstanceTypeBase):type: Literal["unknown"]# Union of all possible CircumstanceTypes with 'type' as the discriminatorCircumstanceType = Union[29 unmodified linesAccidentalDrowning,OtherNaturalCause,UnknownNaturalCause,UnknownCircumstance,]# Main Circumstance classclass Circumstances(BaseModel):circumstance_radio: str # e.g., "Yes"circumstance: Optional[str] = None # e.g., "COLLISION"circumstance_type: Optional[CircumstanceType] = Field(None, discriminator="type")# Example usage6 unmodified lines# }# }# circumstance_instance = Circumstance(**json_data)# circumstance_schema = Circumstance.schema_json(indent=2)
1 unmodified line234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101 unmodified linefrom dotenv import load_dotenvimport osload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv('PATH_ASSETS')PATH_ICONS = PATH + PATH_ASSETS + "icons/"contact_text = """# ContactsYou have an animal alive or dead in front of you and you do not know what to do?Please call the contact below corresponding to your canton. (Cantons are in alphabetical order.)## AG: Aargau117 | Departement Bau, Verkehr und Umwelt, Abteilung Wald, Sektion Jagd und Fischerei## AI: Appenzell Innerrhoden071 788 92 87 | Bau- und Umweltdepartement, Amt für Umwelt, Fachstelle Jagd und Fischerei## AR: Appenzell Ausserrhoden079 698 19 16 |Departement Bau und Volkswirtschaft, Amt für Raum und Wald, Abteilung Natur und Wildtiere## BE: Bern0800 940 100 | Wirtschafts-, Energie- und Umweltdirektion## BL: Basel-Landschaft061 922 03 66, 061 552 56 59 | Volkswirtschafts- und Gesundheitsdirektion, Amt für Wald und Wild beider Basel## BS: Basel-Stadt061 922 03 66, 061 552 56 59 | Volkswirtschafts- und Gesundheitsdirektion, Amt für Wald und Wild beider Basel## FR: Fribourg026 305 23 31 | Energie, Landwirtschaft und Umwelt, Amt für Wald und Natur, Sektion Fauna, Jagd und Fischerei## GE: Geneva022 388 55 00 | Office cantonal de l'agriculture et de la nature, Centrale d'engagement et des transmissions (CET)## GL: GlarusVerwaltung Bau und Umwelt, Umwelt, Wald und Energie, Jagd und Fischerei## GR: Graubünden055 645 66 66 | Amt für Jagd und Fischerei Jagdbezirke - Über uns## JU: Jura032 420 48 00, 032 420 65 65 | Departement de l'environnement, Office de l'environnement, Chasse et protection de la faune sauvage## LU: Luzern041 248 81 17, 117 | Bau-, Umwelt- und Wirtschaftsdepartement, Landwirtschaft und Wald, Jagd, Wildhut und Jagdaufsicht## NE: Neuchatel032 889 67 80 | Service de la faune, des fôrets et de la nature, faune## NW: Nidwalden041 618 44 66 | Justiz- und Sicherheitsdirektion, Amt für Justiz, Abteilung Jagd und Fischerei## OW: Obwalden041 666 64 76 | Bau- und Raumentwicklungsdepartement, Amt für Wald und Landschaft, Wildtiere und Jagd## SG: St. Gallen117 | Volkwirtschaftsdepartement, Amt für Natur, Jagd und Fischerei## SH: Schaffhausen052 632 74 66 | Departement des Innern, Jagd und Fischerei## SO: Solothurn117| Volkswirtschaftdepartement, Amt für Wald, Jagd und Fischerei## SZ: Schwyz041 819 29 29 | Umweltdepartement, Amt für Wald und Natur, Jagd und Wildtiere## TG: Thurgau058 345 61 50 | Jagd- und Fischereiverwaltung## TI: Ticino091 814 28 71 | Divisione dell'ambiente, Ufficio della caccia e della pesca## UR: Uri041 875 2316 | Sicherheitsdirektion, Amt für Forst und Jagd## VD: Vaud021 557 88 55 | Environnement, Biodiversité et paysage, Police Faune-nature## VS: Valais027 606 70 00, 117 | Umwelt, Energie und Landwirtschaft, Dienststelle für Jagd, Fischerei und Wildtiere## ZG: Zug041 595 41 41 | Natur, Umwelt und Tiere, Arten, Lebensräume, Wildhut und Fischereiaufsicht"""with gr.Blocks(theme='shivi/calm_seafoam') as contacts:with gr.Row(scale = 1):gr.Image(PATH_ICONS+"help.png", height=300,interactive=False,show_fullscreen_button = False, show_share_button=False,show_download_button=False, show_label=False)gr.Image(PATH_ICONS+"contact-information.png", height=300,interactive=False,show_fullscreen_button = False, show_share_button=False,show_download_button=False, show_label=False)gr.Image(PATH_ICONS+"question.png", height=300,interactive=False,show_fullscreen_button = False, show_share_button=False,show_download_button=False, show_label=False)gr.Markdown(contact_text, show_label=False)1 unmodified line234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251 unmodified linefrom dotenv import load_dotenvimport osload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv("PATH_ASSETS")PATH_ICONS = PATH + PATH_ASSETS + "icons/"contact_text = """# ContactsYou have an animal alive or dead in front of you and you do not know what to do?Please call the contact below corresponding to your canton. (Cantons are in alphabetical order.)## AG: Aargau117 | Departement Bau, Verkehr und Umwelt, Abteilung Wald, Sektion Jagd und Fischerei## AI: Appenzell Innerrhoden071 788 92 87 | Bau- und Umweltdepartement, Amt für Umwelt, Fachstelle Jagd und Fischerei## AR: Appenzell Ausserrhoden079 698 19 16 |Departement Bau und Volkswirtschaft, Amt für Raum und Wald, Abteilung Natur und Wildtiere## BE: Bern0800 940 100 | Wirtschafts-, Energie- und Umweltdirektion## BL: Basel-Landschaft061 922 03 66, 061 552 56 59 | Volkswirtschafts- und Gesundheitsdirektion, Amt für Wald und Wild beider Basel## BS: Basel-Stadt061 922 03 66, 061 552 56 59 | Volkswirtschafts- und Gesundheitsdirektion, Amt für Wald und Wild beider Basel## FR: Fribourg026 305 23 31 | Energie, Landwirtschaft und Umwelt, Amt für Wald und Natur, Sektion Fauna, Jagd und Fischerei## GE: Geneva022 388 55 00 | Office cantonal de l'agriculture et de la nature, Centrale d'engagement et des transmissions (CET)## GL: GlarusVerwaltung Bau und Umwelt, Umwelt, Wald und Energie, Jagd und Fischerei## GR: Graubünden055 645 66 66 | Amt für Jagd und Fischerei Jagdbezirke - Über uns## JU: Jura032 420 48 00, 032 420 65 65 | Departement de l'environnement, Office de l'environnement, Chasse et protection de la faune sauvage## LU: Luzern041 248 81 17, 117 | Bau-, Umwelt- und Wirtschaftsdepartement, Landwirtschaft und Wald, Jagd, Wildhut und Jagdaufsicht## NE: Neuchatel032 889 67 80 | Service de la faune, des fôrets et de la nature, faune## NW: Nidwalden041 618 44 66 | Justiz- und Sicherheitsdirektion, Amt für Justiz, Abteilung Jagd und Fischerei## OW: Obwalden041 666 64 76 | Bau- und Raumentwicklungsdepartement, Amt für Wald und Landschaft, Wildtiere und Jagd## SG: St. Gallen117 | Volkwirtschaftsdepartement, Amt für Natur, Jagd und Fischerei## SH: Schaffhausen052 632 74 66 | Departement des Innern, Jagd und Fischerei## SO: Solothurn117| Volkswirtschaftdepartement, Amt für Wald, Jagd und Fischerei## SZ: Schwyz041 819 29 29 | Umweltdepartement, Amt für Wald und Natur, Jagd und Wildtiere## TG: Thurgau058 345 61 50 | Jagd- und Fischereiverwaltung## TI: Ticino091 814 28 71 | Divisione dell'ambiente, Ufficio della caccia e della pesca## UR: Uri041 875 2316 | Sicherheitsdirektion, Amt für Forst und Jagd## VD: Vaud021 557 88 55 | Environnement, Biodiversité et paysage, Police Faune-nature## VS: Valais027 606 70 00, 117 | Umwelt, Energie und Landwirtschaft, Dienststelle für Jagd, Fischerei und Wildtiere## ZG: Zug041 595 41 41 | Natur, Umwelt und Tiere, Arten, Lebensräume, Wildhut und Fischereiaufsicht"""with gr.Blocks(theme="shivi/calm_seafoam") as contacts:with gr.Row(scale=1):gr.Image(PATH_ICONS + "help.png",height=300,interactive=False,show_fullscreen_button=False,show_share_button=False,show_download_button=False,show_label=False,)gr.Image(PATH_ICONS + "contact-information.png",height=300,interactive=False,show_fullscreen_button=False,show_share_button=False,show_download_button=False,show_label=False,)gr.Image(PATH_ICONS + "question.png",height=300,interactive=False,show_fullscreen_button=False,show_share_button=False,show_download_button=False,show_label=False,)gr.Markdown(contact_text, show_label=False)
6 unmodified lines78910111213141516171819202122232425262728293031323334353637383940414243444546474849505152536 unmodified linesfrom dotenv import load_dotenvimport osload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv('PATH_ASSETS')PATH_ICONS = PATH + PATH_ASSETS + "icons/"def show_section_dead(visible, mode, individual):if visible==True:individual = add_data_to_individual("wounded_state", "No", individual)individual = add_data_to_individual("dead_state", "Yes", individual)with gr.Column(visible=visible, elem_id="dead") as section_dead:gr.Markdown("## The animal is dead.")gr.Button("Do you know what conditions caused this?",icon=PATH_ICONS + "eye.png",variant= "primary")# gr.Markdown("## Do you know what conditions caused this?", label="description")radio_cause = gr.Radio(["Yes", "No"], value=None, show_label=False, interactive=True)button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_circumstances(visible=False)gr.Button("Are there physical changes on the animal?",icon=PATH_ICONS + "cardiogram.png",variant= "primary")radio_physical = gr.Radio(["Yes", "No"], value=None, show_label=False, interactive=True)with gr.Row():physical_boxes = create_bird_anatomy(False, "dead")with gr.Column():checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs = process_body_parts("dead", mode, "None")gr.Button("Follow-Up Events",icon=PATH_ICONS + "schedule.png",variant= "primary")gr.Markdown("Please tell us what you did with the animal.", label="description")with gr.Row():fe_collection_dropdown, fe_recepient_dropdown, fe_radio_dropdown, fe_answer_dropdown = create_followup_dropdowns(visible, "dead")with gr.Row():fe_name_recipient, fe_collection_ref = create_followup_open(visible, "dead")return section_dead, individual, radio_cause, radio_physical,\button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, \dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2, \physical_boxes, \checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs, \fe_collection_dropdown, fe_recepient_dropdown, fe_radio_dropdown, fe_answer_dropdown, fe_name_recipient, fe_collection_ref6 unmodified lines7891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111126 unmodified linesfrom dotenv import load_dotenvimport osload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv("PATH_ASSETS")PATH_ICONS = PATH + PATH_ASSETS + "icons/"def show_section_dead(visible, mode, individual):if visible == True:individual = add_data_to_individual("wounded_state", "No", individual)individual = add_data_to_individual("dead_state", "Yes", individual)with gr.Column(visible=visible, elem_id="dead") as section_dead:gr.Markdown("## The animal is dead.")gr.Button("Do you know what conditions caused this?",icon=PATH_ICONS + "eye.png",variant="primary",)# gr.Markdown("## Do you know what conditions caused this?", label="description")radio_cause = gr.Radio(["Yes", "No"], value=None, show_label=False, interactive=True)(button_collision,button_deliberate_destruction,button_indirect_destruction,button_natural_cause,dropdown,dropdown_level2,openfield_level2,dropdown_extra_level2,) = create_circumstances(visible=False)gr.Button("Are there physical changes on the animal?",icon=PATH_ICONS + "cardiogram.png",variant="primary",)radio_physical = gr.Radio(["Yes", "No"], value=None, show_label=False, interactive=True)with gr.Row():physical_boxes = create_bird_anatomy(False, "dead")with gr.Column():(checkbox_beak,text_beak,checkbox_body,text_body,checkbox_feathers,text_feathers,checkbox_head,text_head,checkbox_legs,text_legs,) = process_body_parts("dead", mode, "None")gr.Button("Follow-Up Events", icon=PATH_ICONS + "schedule.png", variant="primary")gr.Markdown("Please tell us what you did with the animal.", label="description")with gr.Row():(fe_collection_dropdown,fe_recepient_dropdown,fe_radio_dropdown,fe_answer_dropdown,) = create_followup_dropdowns(visible, "dead")with gr.Row():fe_name_recipient, fe_collection_ref = create_followup_open(visible, "dead")return (section_dead,individual,radio_cause,radio_physical,button_collision,button_deliberate_destruction,button_indirect_destruction,button_natural_cause,dropdown,dropdown_level2,openfield_level2,dropdown_extra_level2,physical_boxes,checkbox_beak,text_beak,checkbox_body,text_body,checkbox_feathers,text_feathers,checkbox_head,text_head,checkbox_legs,text_legs,fe_collection_dropdown,fe_recepient_dropdown,fe_radio_dropdown,fe_answer_dropdown,fe_name_recipient,fe_collection_ref,)
3 unmodified lines456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263643 unmodified linesfrom physical.physical_checkbox import process_body_partsfrom behavior.behavior_checkbox import create_behavior_checkboxfrom follow_up.followup_events import create_followup_dropdowns, create_followup_openfrom validation_submission.utils_individual import add_data_to_individualfrom dotenv import load_dotenvimport osload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv('PATH_ASSETS')PATH_ICONS = PATH + PATH_ASSETS + "icons/"def show_section_wounded(visible, mode, individual):if visible==True:individual = add_data_to_individual("wounded_state", "Yes", individual)individual = add_data_to_individual("dead_state", "No", individual)with gr.Column(visible=visible, elem_id="wounded") as wounded_section:gr.Markdown("## The animal is wounded / sick.")gr.Button("Do you know what conditions caused this?",icon=PATH_ICONS + "eye.png",variant= "primary")radio_cause = gr.Radio(["Yes", "No"], value=None, show_label=False, interactive=True)button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_circumstances(visible=False)gr.Button("Is the animal displaying behavioural changes?",icon=PATH_ICONS + "neuron.png",variant= "primary")radio_behaviour = gr.Radio(["Yes", "No"], value=None, show_label=False, interactive=True)with gr.Row():behavior_checkbox, behavior_text = create_behavior_checkbox("wounded", mode, False)gr.Button("Are there physical changes on the animal?",icon=PATH_ICONS + "cardiogram.png",variant= "primary")radio_physical = gr.Radio(["Yes", "No"], value=None, show_label=False, interactive=True)with gr.Row():physical_boxes = create_bird_anatomy(False, "wounded")with gr.Column():checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs = process_body_parts("wounded", mode, "None")gr.Button("Follow-Up Events",icon=PATH_ICONS + "schedule.png",variant= "primary")gr.Markdown("Please tell us what you did with the animal.", label="description")with gr.Row():fe_collection_dropdown, fe_recepient_dropdown, fe_radio_dropdown, fe_answer_dropdown = create_followup_dropdowns(visible, "wounded")with gr.Row():fe_name_recipient, fe_collection_ref = create_followup_open(visible, "wounded")# Change variables and namesreturn wounded_section, individual, radio_cause, radio_behaviour, radio_physical, \button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause, \dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2, \behavior_checkbox, behavior_text, \physical_boxes, \checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs, \fe_collection_dropdown, fe_recepient_dropdown, fe_radio_dropdown, fe_answer_dropdown, fe_name_recipient, fe_collection_ref3 unmodified lines4567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311323 unmodified linesfrom physical.physical_checkbox import process_body_partsfrom behavior.behavior_checkbox import create_behavior_checkboxfrom follow_up.followup_events import create_followup_dropdowns, create_followup_openfrom validation_submission.utils_individual import add_data_to_individualfrom dotenv import load_dotenvimport osload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv("PATH_ASSETS")PATH_ICONS = PATH + PATH_ASSETS + "icons/"def show_section_wounded(visible, mode, individual):if visible == True:individual = add_data_to_individual("wounded_state", "Yes", individual)individual = add_data_to_individual("dead_state", "No", individual)with gr.Column(visible=visible, elem_id="wounded") as wounded_section:gr.Markdown("## The animal is wounded / sick.")gr.Button("Do you know what conditions caused this?",icon=PATH_ICONS + "eye.png",variant="primary",)radio_cause = gr.Radio(["Yes", "No"], value=None, show_label=False, interactive=True)(button_collision,button_deliberate_destruction,button_indirect_destruction,button_natural_cause,dropdown,dropdown_level2,openfield_level2,dropdown_extra_level2,) = create_circumstances(visible=False)gr.Button("Is the animal displaying behavioural changes?",icon=PATH_ICONS + "neuron.png",variant="primary",)radio_behaviour = gr.Radio(["Yes", "No"], value=None, show_label=False, interactive=True)with gr.Row():behavior_checkbox, behavior_text = create_behavior_checkbox("wounded", mode, False)gr.Button("Are there physical changes on the animal?",icon=PATH_ICONS + "cardiogram.png",variant="primary",)radio_physical = gr.Radio(["Yes", "No"], value=None, show_label=False, interactive=True)with gr.Row():physical_boxes = create_bird_anatomy(False, "wounded")with gr.Column():(checkbox_beak,text_beak,checkbox_body,text_body,checkbox_feathers,text_feathers,checkbox_head,text_head,checkbox_legs,text_legs,) = process_body_parts("wounded", mode, "None")gr.Button("Follow-Up Events", icon=PATH_ICONS + "schedule.png", variant="primary")gr.Markdown("Please tell us what you did with the animal.", label="description")with gr.Row():(fe_collection_dropdown,fe_recepient_dropdown,fe_radio_dropdown,fe_answer_dropdown,) = create_followup_dropdowns(visible, "wounded")with gr.Row():fe_name_recipient, fe_collection_ref = create_followup_open(visible, "wounded")# Change variables and namesreturn (wounded_section,individual,radio_cause,radio_behaviour,radio_physical,button_collision,button_deliberate_destruction,button_indirect_destruction,button_natural_cause,dropdown,dropdown_level2,openfield_level2,dropdown_extra_level2,behavior_checkbox,behavior_text,physical_boxes,checkbox_beak,text_beak,checkbox_body,text_body,checkbox_feathers,text_feathers,checkbox_head,text_head,checkbox_legs,text_legs,fe_collection_dropdown,fe_recepient_dropdown,fe_radio_dropdown,fe_answer_dropdown,fe_name_recipient,fe_collection_ref,)
2 unmodified lines345678910111213141516171819202122232425262728293031323334353637383940414243444546474849502 unmodified lines# --- Event follow-up classes ---class AnimalCollectedEvent(BaseModel):type: Literal['animal collected']collected: Literal['yes', 'no']class RecipientEvent(BaseModel):type: Literal['recipient']recipient: Literal['veterinary', 'care center','local museum', 'national museum','other']class RadiographyEvent(BaseModel):type: Literal['radiography']radiography: Literal['yes', 'no', 'unknown']class GivenAnswerEvent(BaseModel):type: Literal['given answer']answer: Literal['nothing','complaint against x','complaint','police call','discussion with the speaker','press release','unknown']class NameOfRecipientEvent(BaseModel):type: Literal['recipient name']name: strclass CollectionReferenceEvent(BaseModel):type: Literal['collection reference']reference: strFollowUpEventType = Union[AnimalCollectedEvent,RecipientEvent,RadiographyEvent,GivenAnswerEvent,NameOfRecipientEvent,CollectionReferenceEvent]class FollowUpEvents(BaseModel):follow_up_events: Optional[List[FollowUpEventType]] = None2 unmodified lines3456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657582 unmodified lines# --- Event follow-up classes ---class AnimalCollectedEvent(BaseModel):type: Literal["animal collected"]collected: Literal["yes", "no"]class RecipientEvent(BaseModel):type: Literal["recipient"]recipient: Literal["veterinary", "care center", "local museum", "national museum", "other"]class RadiographyEvent(BaseModel):type: Literal["radiography"]radiography: Literal["yes", "no", "unknown"]class GivenAnswerEvent(BaseModel):type: Literal["given answer"]answer: Literal["nothing","complaint against x","complaint","police call","discussion with the speaker","press release","unknown",]class NameOfRecipientEvent(BaseModel):type: Literal["recipient name"]name: strclass CollectionReferenceEvent(BaseModel):type: Literal["collection reference"]reference: strFollowUpEventType = Union[AnimalCollectedEvent,RecipientEvent,RadiographyEvent,GivenAnswerEvent,NameOfRecipientEvent,CollectionReferenceEvent,]class FollowUpEvents(BaseModel):follow_up_events: Optional[List[FollowUpEventType]] = None
1 unmodified line2345678910111213141516171819202122232425262728293031323334353637383940414243444546471 unmodified linefrom utils.utils_config import get_custom_config_dropdownsfrom validation_submission.utils_individual import add_data_to_individualdef create_followup_dropdowns(visible, elem_id):followup_config = get_custom_config_dropdowns("config_followup.json")followup_config = followup_config["Event follow-up"]fe_collection_dropdown = create_fe_collection_dropdown(followup_config, visible, elem_id)fe_recipient_dropdown = create_fe_recipient_dropdown(followup_config, visible, elem_id)fe_radio_dropdown = create_fe_radio_dropdown(followup_config, visible, elem_id)fe_answer_dropdown = create_fe_answer_dropdown(followup_config, visible, elem_id)return fe_collection_dropdown, fe_recipient_dropdown, fe_radio_dropdown, fe_answer_dropdowndef create_followup_open(visible, elem_id):fe_name_recipient = gr.Textbox(label="Name of recipient / museum", visible=visible,elem_id=elem_id, interactive=True)fe_collection_ref = gr.Textbox(label="Collection reference", visible=visible,elem_id=elem_id, interactive=True)return fe_name_recipient, fe_collection_refdef create_fe_collection_dropdown(followup_config, visible, elem_id):fe_collection_dropdown = gr.Dropdown(choices=followup_config["Animal collected"]["Options"], label="Animal collected",visible=visible, elem_id=elem_id, interactive=True)return fe_collection_dropdowndef create_fe_recipient_dropdown(followup_config, visible, elem_id):fe_recipient_dropdown = gr.Dropdown(choices=followup_config["Recipient"]["Options"], label="Recipient",visible=visible, elem_id=elem_id, interactive=True)return fe_recipient_dropdowndef create_fe_radio_dropdown(followup_config, visible, elem_id):fe_radio_dropdown = gr.Dropdown(choices=followup_config["Radiography"]["Options"], label="Radiography",visible=visible, elem_id=elem_id, interactive=True)return fe_radio_dropdowndef create_fe_answer_dropdown(followup_config, visible, elem_id):fe_answer_dropdown = gr.Dropdown(choices=followup_config["Given answer"]["Options"], label="Given answer",visible=visible, elem_id=elem_id, interactive=True)return fe_answer_dropdowndef save_fe(value, key, individual):individual = add_data_to_individual("wounded_dead", "followup " + key.lower(), value.lower())return individual1 unmodified line2345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485861 unmodified linefrom utils.utils_config import get_custom_config_dropdownsfrom validation_submission.utils_individual import add_data_to_individualdef create_followup_dropdowns(visible, elem_id):followup_config = get_custom_config_dropdowns("config_followup.json")followup_config = followup_config["Event follow-up"]fe_collection_dropdown = create_fe_collection_dropdown(followup_config, visible, elem_id)fe_recipient_dropdown = create_fe_recipient_dropdown(followup_config, visible, elem_id)fe_radio_dropdown = create_fe_radio_dropdown(followup_config, visible, elem_id)fe_answer_dropdown = create_fe_answer_dropdown(followup_config, visible, elem_id)return (fe_collection_dropdown,fe_recipient_dropdown,fe_radio_dropdown,fe_answer_dropdown,)def create_followup_open(visible, elem_id):fe_name_recipient = gr.Textbox(label="Name of recipient / museum",visible=visible,elem_id=elem_id,interactive=True,)fe_collection_ref = gr.Textbox(label="Collection reference", visible=visible, elem_id=elem_id, interactive=True)return fe_name_recipient, fe_collection_refdef create_fe_collection_dropdown(followup_config, visible, elem_id):fe_collection_dropdown = gr.Dropdown(choices=followup_config["Animal collected"]["Options"],label="Animal collected",visible=visible,elem_id=elem_id,interactive=True,)return fe_collection_dropdowndef create_fe_recipient_dropdown(followup_config, visible, elem_id):fe_recipient_dropdown = gr.Dropdown(choices=followup_config["Recipient"]["Options"],label="Recipient",visible=visible,elem_id=elem_id,interactive=True,)return fe_recipient_dropdowndef create_fe_radio_dropdown(followup_config, visible, elem_id):fe_radio_dropdown = gr.Dropdown(choices=followup_config["Radiography"]["Options"],label="Radiography",visible=visible,elem_id=elem_id,interactive=True,)return fe_radio_dropdowndef create_fe_answer_dropdown(followup_config, visible, elem_id):fe_answer_dropdown = gr.Dropdown(choices=followup_config["Given answer"]["Options"],label="Given answer",visible=visible,elem_id=elem_id,interactive=True,)return fe_answer_dropdowndef save_fe(value, key, individual):individual = add_data_to_individual("wounded_dead", "followup " + key.lower(), value.lower())return individual
12345678910111213141516from pydantic import BaseModel, Fieldfrom typing import Literal, List, Union, Optionalclass Longitude(BaseModel):type: Literal['longitude']value: floatclass Latitude(BaseModel):type: Literal['latitude']value: floatclass Geolocalisation(BaseModel):longitude: Longitudelatitude: Latitudename: Optional[str]123456789101112131415161718from pydantic import BaseModel, Fieldfrom typing import Literal, List, Union, Optionalclass Longitude(BaseModel):type: Literal["longitude"]value: floatclass Latitude(BaseModel):type: Literal["latitude"]value: floatclass Geolocalisation(BaseModel):longitude: Longitudelatitude: Latitudename: Optional[str]
12345628 unmodified lines3536373839402 unmodified lines434445464748495051525354import gradio as grimport jsonfrom geolocalisation.maps import create_geolocalisation_object, save_geolocalisation_to_json# JavaScript code to get location and update hidden_inputjs_geocode = """28 unmodified lines}"""def display_location(location_json, individual):geo_dict = json.loads(location_json)if "latitude" in geo_dict.keys():2 unmodified linesgeolocalisation = create_geolocalisation_object(latitude, longitude, "NA")individual = save_geolocalisation_to_json(geolocalisation, individual)geo_text = f"Latitude: {latitude} | Longitude: {longitude}"else:error = geo_dict["error"]geo_text = f"Error occured ({error}). Give your browser permission to use your geolocalisation or change browsers."locationtext = gr.Textbox(geo_text,visible=True,show_label=False,interactive=False)return locationtext, individual12345678928 unmodified lines383940414243442 unmodified lines47484950515253545556import gradio as grimport jsonfrom geolocalisation.maps import (create_geolocalisation_object,save_geolocalisation_to_json,)# JavaScript code to get location and update hidden_inputjs_geocode = """28 unmodified lines}"""def display_location(location_json, individual):geo_dict = json.loads(location_json)if "latitude" in geo_dict.keys():2 unmodified linesgeolocalisation = create_geolocalisation_object(latitude, longitude, "NA")individual = save_geolocalisation_to_json(geolocalisation, individual)geo_text = f"Latitude: {latitude} | Longitude: {longitude}"else:error = geo_dict["error"]geo_text = f"Error occured ({error}). Give your browser permission to use your geolocalisation or change browsers."locationtext = gr.Textbox(geo_text, visible=True, show_label=False, interactive=False)return locationtext, individual
3 unmodified lines4567891011121314151617181920212223242526272829303132332 unmodified lines363738394041424344454647484950513 unmodified linesfrom geolocalisation.class_geolocalisation import Geolocalisationdef create_geolocalisation_object(lat, long, name):try:geolocalisation = Geolocalisation(longitude={"type": "longitude", "value": long},latitude={"type": "latitude", "value": lat},name=name)except:print("Pydantic Error for Geolocalisation")return geolocalisationdef save_geolocalisation_to_json(geolocalisation, individual):geo_dict = geolocalisation.dict()individual = add_data_to_individual("geolocalisation", geo_dict, individual)return individualdef get_location(address, individual):try:# calling the Nominatim toolloc = Nominatim(user_agent="GetLoc")# entering the location namegetLoc = loc.geocode(address)# latitude and longitudelat = getLoc.latitudelon = getLoc.longitude2 unmodified linesgeolocalisation = create_geolocalisation_object(lat, lon, address)individual = save_geolocalisation_to_json(geolocalisation, individual)#display location processingvalue = "Latitude = " + str(lat) + "\n" + "Longitude = " + str(lon)identified_location= gr.Textbox(visible=True, interactive=False,label="Identified GPS Location",value=value)return identified_location, individualexcept:error = "Please try another less precise location."identified_location= gr.Textbox(visible=True, interactive=False,label="Identified GPS Location",value=error)return identified_location, individual3 unmodified lines45678910111213141516171819202122232425262728293031323334352 unmodified lines383940414243444546474849505152535455565758593 unmodified linesfrom geolocalisation.class_geolocalisation import Geolocalisationdef create_geolocalisation_object(lat, long, name):try:geolocalisation = Geolocalisation(longitude={"type": "longitude", "value": long},latitude={"type": "latitude", "value": lat},name=name,)except:print("Pydantic Error for Geolocalisation")return geolocalisationdef save_geolocalisation_to_json(geolocalisation, individual):geo_dict = geolocalisation.dict()individual = add_data_to_individual("geolocalisation", geo_dict, individual)return individualdef get_location(address, individual):try:# calling the Nominatim toolloc = Nominatim(user_agent="GetLoc")# entering the location namegetLoc = loc.geocode(address)# latitude and longitudelat = getLoc.latitudelon = getLoc.longitude2 unmodified linesgeolocalisation = create_geolocalisation_object(lat, lon, address)individual = save_geolocalisation_to_json(geolocalisation, individual)# display location processingvalue = "Latitude = " + str(lat) + "\n" + "Longitude = " + str(lon)identified_location = gr.Textbox(visible=True,interactive=False,label="Identified GPS Location",value=value,)return identified_location, individualexcept:error = "Please try another less precise location."identified_location = gr.Textbox(visible=True,interactive=False,label="Identified GPS Location",value=error,)return identified_location, individual
1234567891011121314151617import gradio as grfrom datasets import disable_cachingdisable_caching()from mode_advanced import advancedfrom mode_simple import simplefrom contacts import contactsfrom about import aboutdemo = gr.TabbedInterface([simple, advanced, contacts, about],["Simple Mode" , "Advanced Reporting", "Cantonal Contacts", "About"],theme='shivi/calm_seafoam')if __name__ == "__main__":demo.launch(server_name="0.0.0.0", server_port=7860)1234567891011121314151617181920import gradio as grfrom datasets import disable_cachingdisable_caching()from mode_advanced import advancedfrom mode_simple import simplefrom contacts import contactsfrom about import aboutdemo = gr.TabbedInterface([simple, advanced, contacts, about],["Simple Mode", "Advanced Reporting", "Cantonal Contacts", "About"],theme="shivi/calm_seafoam",)if __name__ == "__main__":demo.launch(server_name="0.0.0.0", server_port=7860)
16 unmodified lines17181920212223242526272829303132333435363738394041424344454647484950515253545556571 unmodified line5960616263646566676869703 unmodified lines747576777879808182838485868788892 unmodified lines92939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501512 unmodified lines1541551561571581591601611621631641651661671681691701711721731741751761771 unmodified line1791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462471 unmodified line2492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932941 unmodified line29629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345416 unmodified linesfrom validation_submission.utils_individual import add_data_to_individualfrom validation_submission.submission import validate_save_individualfrom validation_submission.utils_save import save_details, save_imagefrom validation_submission.resets import reset_individual, reset_error_box, hide_physicalfrom dotenv import load_dotenvimport osload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv('PATH_ASSETS')PATH_ICONS = PATH + PATH_ASSETS + "icons/"with gr.Blocks(theme='shivi/calm_seafoam') as advanced:mode = "advanced"individual = gr.State({})individual.value = add_data_to_individual("image_md5", generate_random_md5(), individual.value)# ---------------------------------------------------------# Header Textwith gr.Row():gr.Image(PATH_ICONS+"impact.png", scale =0.1,interactive=False,show_fullscreen_button = False, show_share_button=False,show_download_button=False, show_label=False)with gr.Column(scale=1):title = gr.Markdown("# Welcome to Digiwild - Advanced Reporting", label="Title")description = gr.Markdown("### Please record your wildlife observations here !", label="description")# ---------------------------------------------------------# Camerawith gr.Row():camera = gr.Image(elem_id="image")camera.input(save_image, inputs=[camera, individual], outputs=[individual])# ---------------------------------------------------------# General Detailswith gr.Column(scale=1):gr.Button("General Details", icon=PATH_ICONS+"chicken.png", variant="secondary")with gr.Row():specie = gr.Textbox(1 unmodified lineplaceholder="e.g. European Robin, Common Blackbird",info="Enter the species name if you can identify it. If unsure, provide your best guess or general description (e.g. 'small brown bird')",visible=True,interactive=True)specie.change(save_details,inputs=[gr.Textbox("specie", visible=False),specie],outputs=individual)# Number of individualswith gr.Row():3 unmodified linesminimum=1,precision=0, # Only whole numbersinfo="Enter the number of animals observed",#placeholder="Enter number...",visible=True,interactive=True)num_individuals.change(save_details,inputs=[gr.Textbox("number", visible=False),num_individuals],outputs=individual)# Introducing text_box for commentswith gr.Row():comments = gr.TextArea(label="Additional Comments",2 unmodified lineslines=3,max_lines=5,visible=True,interactive=True)comments.change(save_details,inputs=[gr.Textbox("comments", visible=False),comments],outputs=individual)# ---------------------------------------------------------# Locationgr.Button("Location", icon=PATH_ICONS+"pin.png", variant="secondary")with gr.Row():with gr.Column(scale=1):gr.Markdown("#### Location (Using address)")location = gr.Textbox(visible=True, interactive=True,label="Location of Sighting")#display location processingidentified_location= gr.Textbox(visible=False, interactive=False,label="Identified GPS Location")with gr.Row():#to submit itsubmit_location = gr.Button("Get Coordinates using address",visible=True, interactive=True, scale=3)submit_location.click(get_location, inputs=[location, individual], outputs=[identified_location, individual])#to clear itclear_location = gr.ClearButton(components=[location, identified_location],visible=True, interactive=True, scale=1)clear_location.click()with gr.Column(scale=1):# Geolocationgr.Button("Location", icon=PATH_ICONS+"pin.png", variant="primary")location_data = gr.JSON(label="Identified GPS Location", visible=False)hidden_input = gr.Textbox(visible=False, elem_id="textbox_id")locationtext = gr.Textbox(visible=False, elem_id="textbox_id")btn_gpslocation = gr.Button("Get Coordinates using GPS (Permission required - May take a few seconds)")btn_gpslocation.click(None, [], [], js=js_geocode)hidden_input.change(display_location,inputs=[hidden_input, individual],outputs=[locationtext, individual])# ---------------------------------------------------------# Dead and Wounded Buttonsgr.Button("State of the Animal", variant="secondary")with gr.Row():gr.Image(PATH_ICONS+"medical-app.png", scale =0.1,interactive=False,show_fullscreen_button = False, show_share_button=False,show_download_button=False, show_label=False)with gr.Column():gr.Markdown("## The State of the Animal", label="Title")gr.Markdown("Please tell us if the animal was wounded / sick or dead.", label="description")gr.Markdown("Please fill out as many fields as you can, based on what you can see.", label="description")gr.Markdown("### Do not touch the animal unless absolutely necessary.", label="description")with gr.Row() as block_form:with gr.Column(scale=1):butt_wounded = gr.Button("Wounded / Sick", elem_id="wounded")2 unmodified lines# ---------------------------------------------------------# Initiate sectionssection_dead, individual, radio_circumstance_dead, radio_physical_dead,\button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \physical_boxes_dead, \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, \fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \fe_name_recipient_dead, fe_collection_ref_dead \= show_section_dead(False, mode, individual)section_wounded, individual, radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded, \button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \behavior_checkbox, behavior_text, \physical_boxes_wounded, \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, \fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \fe_name_recipient_wounded, fe_collection_ref_wounded \= show_section_wounded(False, mode, individual)# ---------------------------------------------------------# ---------------------------------------------------------1 unmodified line# Dead Button Logicpartial_show_section_dead = partial(show_section_dead, True)partial_hide_section_wounded = partial(show_section_wounded, False)butt_dead.click(partial_show_section_dead,inputs=[gr.Text(mode, visible=False),individual],outputs=[section_dead,individual,radio_circumstance_dead, radio_physical_dead,button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \physical_boxes_dead, \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, \fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \fe_name_recipient_dead, fe_collection_ref_dead \])butt_dead.click(partial_hide_section_wounded,inputs=[gr.Text(mode, visible=False),individual],outputs=[section_wounded,individual,radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,behavior_checkbox, behavior_text,physical_boxes_wounded, \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, \fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \fe_name_recipient_wounded, fe_collection_ref_wounded \])# ---------------------------------------------------------# Wounded Button Logicpartial_show_section_wounded = partial(show_section_wounded, True)partial_hide_section_dead = partial(show_section_dead, False)butt_wounded.click(partial_show_section_wounded,inputs=[gr.Text(mode, visible=False),individual],outputs=[section_wounded,individual,radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,behavior_checkbox, behavior_text,physical_boxes_wounded, \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, \fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \fe_name_recipient_wounded, fe_collection_ref_wounded \])butt_wounded.click(partial_hide_section_dead,inputs=[gr.Text(mode, visible=False),individual],outputs=[section_dead,individual,radio_circumstance_dead, radio_physical_dead,button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \physical_boxes_dead, \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, \fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \fe_name_recipient_dead, fe_collection_ref_dead \])# ---------------------------------------------------------# ---------------------------------------------------------# ---------------------------------------------------------1 unmodified line# DEAD# ---------------------------------------------------------# Radio Circumstance Deadradio_circumstance_dead.change(fn=show_circumstances,inputs=[radio_circumstance_dead, individual],outputs=[button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])# Dropdowns Deadbutton_collision_dead.click(dropdown_collision,inputs=[individual],outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])button_deliberate_destruction_dead.click(dropdown_deliberate_destruction, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])button_indirect_destruction_dead.click(dropdown_indirect_destruction, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])button_natural_cause_dead.click(dropdown_natural_cause, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])dropdown_dead.select(on_select, inputs=[individual], outputs=[dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])dropdown_level2_dead.select(on_select_dropdown_level2, inputs=[individual], outputs=[individual] )openfield_level2_dead.change(on_change_openfield_level2, inputs=[openfield_level2_dead, individual], outputs=[individual])dropdown_extra_level2_dead.select(on_select_dropdown_extra_level2, inputs=[individual], outputs=[individual])# ---------------------------------------------------------# Radio Physical Deadradio_physical_dead.change(fn=show_physical,inputs=[radio_physical_dead,gr.Text("dead", visible=False),individual],outputs=[physical_boxes_dead, individual])# Checkbox Physical Deadphysical_boxes_dead.select(find_bounding_box,inputs=[physical_boxes_dead, gr.Textbox(value="dead", visible=False)],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])checkbox_beak_dead.select(on_select_body_part, inputs=[checkbox_beak_dead, gr.Text("beak", visible=False), individual], outputs=[individual])checkbox_body_dead.select(on_select_body_part, inputs=[checkbox_body_dead, gr.Text("body", visible=False), individual], outputs=[individual])checkbox_feathers_dead.select(on_select_body_part, inputs=[checkbox_feathers_dead, gr.Text("feathers", visible=False), individual], outputs=[individual])checkbox_head_dead.select(on_select_body_part, inputs=[checkbox_head_dead, gr.Text("head", visible=False), individual], outputs=[individual])checkbox_legs_dead.select(on_select_body_part, inputs=[checkbox_legs_dead, gr.Text("legs", visible=False), individual], outputs=[individual])# ---------------------------------------------------------# ---------------------------------------------------------# ---------------------------------------------------------1 unmodified line# WOUNDED# ---------------------------------------------------------# Radio Circumstance Woundedradio_circumstance_wounded.change(fn=show_circumstances,inputs=[radio_circumstance_wounded, individual],outputs=[button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])# Dropdowns Circumstance Woundedbutton_collision_wounded.click(dropdown_collision,inputs=[individual],outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])button_deliberate_destruction_wounded.click(dropdown_deliberate_destruction, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])button_indirect_destruction_wounded.click(dropdown_indirect_destruction, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])button_natural_cause_wounded.click(dropdown_natural_cause, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])dropdown_wounded.select(on_select, inputs=[individual], outputs=[dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])dropdown_level2_wounded.select(on_select_dropdown_level2, inputs=[individual], outputs=[individual])openfield_level2_wounded.change(on_change_openfield_level2, inputs=[openfield_level2_wounded, individual])dropdown_extra_level2_wounded.select(on_select_dropdown_extra_level2, inputs=[individual], outputs=[individual])# ---------------------------------------------------------# Radio Behavior Woundedradio_behavior_wounded.change(fn=show_behavior,inputs=[radio_behavior_wounded,gr.Text("wounded / sick", visible=False),gr.Text(mode, visible=False),individual],outputs=[behavior_checkbox, behavior_text, individual])behavior_checkbox.select(on_select_behavior,inputs=[behavior_checkbox, individual],outputs=[individual])# ---------------------------------------------------------# Radio Physical Woundedradio_physical_wounded.change(fn=show_physical,inputs=[radio_physical_wounded,gr.Text("wounded / sick", visible=False),individual],outputs=[physical_boxes_wounded, individual])# Checkbox Physical Woundedphysical_boxes_wounded.select(find_bounding_box,inputs=[physical_boxes_wounded, gr.Textbox(value="wounded / sick", visible=False)],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])checkbox_beak_wounded.select(on_select_body_part, inputs=[checkbox_beak_wounded, gr.Text("beak", visible=False), individual], outputs=[individual])checkbox_body_wounded.select(on_select_body_part, inputs=[checkbox_body_wounded, gr.Text("body", visible=False), individual], outputs=[individual])checkbox_feathers_wounded.select(on_select_body_part, inputs=[checkbox_feathers_wounded, gr.Text("feathers", visible=False), individual], outputs=[individual])checkbox_head_wounded.select(on_select_body_part, inputs=[checkbox_head_wounded, gr.Text("head", visible=False), individual], outputs=[individual])checkbox_legs_wounded.select(on_select_body_part, inputs=[checkbox_legs_wounded, gr.Text("legs", visible=False), individual], outputs=[individual])# ---------------------------------------------------------# Follow Up Events Woundedfe_collection_dropdown_wounded.select(save_fe, inputs=[fe_collection_dropdown_wounded, gr.Textbox("animal collected", visible=False), individual], outputs=[individual])fe_recepient_dropdown_wounded.select(save_fe, inputs=[fe_recepient_dropdown_wounded, gr.Textbox("recipient", visible=False), individual],outputs=[individual])fe_radio_dropdown_wounded.select(save_fe, inputs=[fe_radio_dropdown_wounded, gr.Textbox("radiography", visible=False), individual],outputs=[individual])fe_answer_dropdown_wounded.select(save_fe, inputs=[fe_answer_dropdown_wounded, gr.Textbox("given answer", visible=False), individual],outputs=[individual])fe_name_recipient_wounded.input(save_fe, inputs=[fe_name_recipient_wounded, gr.Textbox("recipient name", visible=False), individual],outputs=[individual])fe_collection_ref_wounded.input(save_fe, inputs=[fe_collection_ref_wounded, gr.Textbox("collection reference", visible=False), individual],outputs=[individual])# ---------------------------------------------------------# Follow Up Events Deadfe_collection_dropdown_dead.select(save_fe, inputs=[fe_collection_dropdown_dead, gr.Textbox("animal collected", visible=False), individual],outputs=[individual])fe_recepient_dropdown_dead.select(save_fe, inputs=[fe_recepient_dropdown_dead, gr.Textbox("recipient", visible=False), individual],outputs=[individual])fe_radio_dropdown_dead.select(save_fe, inputs=[fe_radio_dropdown_dead, gr.Textbox("radiography", visible=False), individual],outputs=[individual])fe_answer_dropdown_dead.select(save_fe, inputs=[fe_answer_dropdown_dead, gr.Textbox("given answer", visible=False), individual],outputs=[individual])fe_name_recipient_dead.input(save_fe, inputs=[fe_name_recipient_dead, gr.Textbox("recipient name", visible=False), individual],outputs=[individual])fe_collection_ref_dead.input(save_fe, inputs=[fe_collection_ref_dead, gr.Textbox("collection reference", visible=False), individual], outputs=[individual])# ---------------------------------------------------------# Spacerwith gr.Row(elem_id="centered-row"):gr.Image(PATH_ICONS+"animal.png", height=80, width=80,interactive=False,show_fullscreen_button = False, show_share_button=False,show_download_button=False, show_label=False)advanced.css = """#centered-row {display: flex;justify-content: center;}"""# ---------------------------------------------------------# Error Boxwith gr.Row():error_icon = gr.Image(PATH_ICONS+"chicken.png",height=80, width=80, visible=False,scale=1)error_box = gr.Text(value=None, visible=False, scale=3)# ---------------------------------------------------------# Allow clearing of all previous outputwith gr.Row():button_df = gr.Button("SUBMIT OBSERVATION", icon=PATH_ICONS+"effective.png",scale = 3)button_clear = gr.ClearButton(value="CLEAR",scale = 1,components=[camera,location, identified_location,#dead resetradio_circumstance_dead, radio_physical_dead,button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,dropdown_dead, dropdown_level2_dead,#openfield_level2_dead,dropdown_extra_level2_dead,physical_boxes_dead,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,fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead,fe_name_recipient_dead, fe_collection_ref_dead,#wounded resetradio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,dropdown_wounded, dropdown_level2_wounded,#openfield_level2_wounded,dropdown_extra_level2_wounded,behavior_checkbox, behavior_text,physical_boxes_wounded,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,fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded,fe_name_recipient_wounded, fe_collection_ref_wounded,error_icon, error_box])# ---------------------------------------------------------# VALIDATE ANIMALbutton_df.click(validate_save_individual,inputs=[individual,error_icon,error_box,gr.Text(mode, visible=False)],outputs=[error_icon, error_box])# ---------------------------------------------------------# CLEAR BUTTONbutton_clear.click()button_clear.click(hide_physical,inputs =[gr.Text(mode, visible=False)],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])button_clear.click(hide_physical,inputs =[gr.Text(mode, visible=False)],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])button_clear.click(reset_error_box, inputs=[error_icon, error_box], outputs=[error_icon, error_box])button_clear.click(reset_individual, inputs=[individual], outputs=[individual])16 unmodified lines1718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475761 unmodified line787980818283848586878889903 unmodified lines9495969798991001011021031041051061071081091102 unmodified lines1131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042 unmodified lines2072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772781 unmodified line2802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394401 unmodified line4424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795801 unmodified line58258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100816 unmodified linesfrom validation_submission.utils_individual import add_data_to_individualfrom validation_submission.submission import validate_save_individualfrom validation_submission.utils_save import save_details, save_imagefrom validation_submission.resets import (reset_individual,reset_error_box,hide_physical,)from dotenv import load_dotenvimport osload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv("PATH_ASSETS")PATH_ICONS = PATH + PATH_ASSETS + "icons/"with gr.Blocks(theme="shivi/calm_seafoam") as advanced:mode = "advanced"individual = gr.State({})individual.value = add_data_to_individual("image_md5", generate_random_md5(), individual.value)# ---------------------------------------------------------# Header Textwith gr.Row():gr.Image(PATH_ICONS + "impact.png",scale=0.1,interactive=False,show_fullscreen_button=False,show_share_button=False,show_download_button=False,show_label=False,)with gr.Column(scale=1):title = gr.Markdown("# Welcome to Digiwild - Advanced Reporting", label="Title")description = gr.Markdown("### Please record your wildlife observations here !",label="description",)# ---------------------------------------------------------# Camerawith gr.Row():camera = gr.Image(elem_id="image")camera.input(save_image, inputs=[camera, individual], outputs=[individual])# ---------------------------------------------------------# General Detailswith gr.Column(scale=1):gr.Button("General Details", icon=PATH_ICONS + "chicken.png", variant="secondary")with gr.Row():specie = gr.Textbox(1 unmodified lineplaceholder="e.g. European Robin, Common Blackbird",info="Enter the species name if you can identify it. If unsure, provide your best guess or general description (e.g. 'small brown bird')",visible=True,interactive=True,)specie.change(save_details,inputs=[gr.Textbox("specie", visible=False), specie],outputs=individual,)# Number of individualswith gr.Row():3 unmodified linesminimum=1,precision=0, # Only whole numbersinfo="Enter the number of animals observed",# placeholder="Enter number...",visible=True,interactive=True,)num_individuals.change(save_details,inputs=[gr.Textbox("number", visible=False), num_individuals],outputs=individual,)# Introducing text_box for commentswith gr.Row():comments = gr.TextArea(label="Additional Comments",2 unmodified lineslines=3,max_lines=5,visible=True,interactive=True,)comments.change(save_details,inputs=[gr.Textbox("comments", visible=False), comments],outputs=individual,)# ---------------------------------------------------------# Locationgr.Button("Location", icon=PATH_ICONS + "pin.png", variant="secondary")with gr.Row():with gr.Column(scale=1):gr.Markdown("#### Location (Using address)")location = gr.Textbox(visible=True, interactive=True, label="Location of Sighting")# display location processingidentified_location = gr.Textbox(visible=False, interactive=False, label="Identified GPS Location")with gr.Row():# to submit itsubmit_location = gr.Button("Get Coordinates using address",visible=True,interactive=True,scale=3,)submit_location.click(get_location,inputs=[location, individual],outputs=[identified_location, individual],)# to clear itclear_location = gr.ClearButton(components=[location, identified_location],visible=True,interactive=True,scale=1,)clear_location.click()with gr.Column(scale=1):# Geolocationgr.Button("Location", icon=PATH_ICONS + "pin.png", variant="primary")location_data = gr.JSON(label="Identified GPS Location", visible=False)hidden_input = gr.Textbox(visible=False, elem_id="textbox_id")locationtext = gr.Textbox(visible=False, elem_id="textbox_id")btn_gpslocation = gr.Button("Get Coordinates using GPS (Permission required - May take a few seconds)")btn_gpslocation.click(None, [], [], js=js_geocode)hidden_input.change(display_location,inputs=[hidden_input, individual],outputs=[locationtext, individual],)# ---------------------------------------------------------# Dead and Wounded Buttonsgr.Button("State of the Animal", variant="secondary")with gr.Row():gr.Image(PATH_ICONS + "medical-app.png",scale=0.1,interactive=False,show_fullscreen_button=False,show_share_button=False,show_download_button=False,show_label=False,)with gr.Column():gr.Markdown("## The State of the Animal", label="Title")gr.Markdown("Please tell us if the animal was wounded / sick or dead.",label="description",)gr.Markdown("Please fill out as many fields as you can, based on what you can see.",label="description",)gr.Markdown("### Do not touch the animal unless absolutely necessary.",label="description",)with gr.Row() as block_form:with gr.Column(scale=1):butt_wounded = gr.Button("Wounded / Sick", elem_id="wounded")2 unmodified lines# ---------------------------------------------------------# Initiate sections(section_dead,individual,radio_circumstance_dead,radio_physical_dead,button_collision_dead,button_deliberate_destruction_dead,button_indirect_destruction_dead,button_natural_cause_dead,dropdown_dead,dropdown_level2_dead,openfield_level2_dead,dropdown_extra_level2_dead,physical_boxes_dead,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,fe_collection_dropdown_dead,fe_recepient_dropdown_dead,fe_radio_dropdown_dead,fe_answer_dropdown_dead,fe_name_recipient_dead,fe_collection_ref_dead,) = show_section_dead(False, mode, individual)(section_wounded,individual,radio_circumstance_wounded,radio_behavior_wounded,radio_physical_wounded,button_collision_wounded,button_deliberate_destruction_wounded,button_indirect_destruction_wounded,button_natural_cause_wounded,dropdown_wounded,dropdown_level2_wounded,openfield_level2_wounded,dropdown_extra_level2_wounded,behavior_checkbox,behavior_text,physical_boxes_wounded,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,fe_collection_dropdown_wounded,fe_recepient_dropdown_wounded,fe_radio_dropdown_wounded,fe_answer_dropdown_wounded,fe_name_recipient_wounded,fe_collection_ref_wounded,) = show_section_wounded(False, mode, individual)# ---------------------------------------------------------# ---------------------------------------------------------1 unmodified line# Dead Button Logicpartial_show_section_dead = partial(show_section_dead, True)partial_hide_section_wounded = partial(show_section_wounded, False)butt_dead.click(partial_show_section_dead,inputs=[gr.Text(mode, visible=False), individual],outputs=[section_dead,individual,radio_circumstance_dead,radio_physical_dead,button_collision_dead,button_deliberate_destruction_dead,button_indirect_destruction_dead,button_natural_cause_dead,dropdown_dead,dropdown_level2_dead,openfield_level2_dead,dropdown_extra_level2_dead,physical_boxes_dead,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,fe_collection_dropdown_dead,fe_recepient_dropdown_dead,fe_radio_dropdown_dead,fe_answer_dropdown_dead,fe_name_recipient_dead,fe_collection_ref_dead,],)butt_dead.click(partial_hide_section_wounded,inputs=[gr.Text(mode, visible=False), individual],outputs=[section_wounded,individual,radio_circumstance_wounded,radio_behavior_wounded,radio_physical_wounded,button_collision_wounded,button_deliberate_destruction_wounded,button_indirect_destruction_wounded,button_natural_cause_wounded,dropdown_wounded,dropdown_level2_wounded,openfield_level2_wounded,dropdown_extra_level2_wounded,behavior_checkbox,behavior_text,physical_boxes_wounded,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,fe_collection_dropdown_wounded,fe_recepient_dropdown_wounded,fe_radio_dropdown_wounded,fe_answer_dropdown_wounded,fe_name_recipient_wounded,fe_collection_ref_wounded,],)# ---------------------------------------------------------# Wounded Button Logicpartial_show_section_wounded = partial(show_section_wounded, True)partial_hide_section_dead = partial(show_section_dead, False)butt_wounded.click(partial_show_section_wounded,inputs=[gr.Text(mode, visible=False), individual],outputs=[section_wounded,individual,radio_circumstance_wounded,radio_behavior_wounded,radio_physical_wounded,button_collision_wounded,button_deliberate_destruction_wounded,button_indirect_destruction_wounded,button_natural_cause_wounded,dropdown_wounded,dropdown_level2_wounded,openfield_level2_wounded,dropdown_extra_level2_wounded,behavior_checkbox,behavior_text,physical_boxes_wounded,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,fe_collection_dropdown_wounded,fe_recepient_dropdown_wounded,fe_radio_dropdown_wounded,fe_answer_dropdown_wounded,fe_name_recipient_wounded,fe_collection_ref_wounded,],)butt_wounded.click(partial_hide_section_dead,inputs=[gr.Text(mode, visible=False), individual],outputs=[section_dead,individual,radio_circumstance_dead,radio_physical_dead,button_collision_dead,button_deliberate_destruction_dead,button_indirect_destruction_dead,button_natural_cause_dead,dropdown_dead,dropdown_level2_dead,openfield_level2_dead,dropdown_extra_level2_dead,physical_boxes_dead,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,fe_collection_dropdown_dead,fe_recepient_dropdown_dead,fe_radio_dropdown_dead,fe_answer_dropdown_dead,fe_name_recipient_dead,fe_collection_ref_dead,],)# ---------------------------------------------------------# ---------------------------------------------------------# ---------------------------------------------------------1 unmodified line# DEAD# ---------------------------------------------------------# Radio Circumstance Deadradio_circumstance_dead.change(fn=show_circumstances,inputs=[radio_circumstance_dead, individual],outputs=[button_collision_dead,button_deliberate_destruction_dead,button_indirect_destruction_dead,button_natural_cause_dead,dropdown_dead,dropdown_level2_dead,openfield_level2_dead,dropdown_extra_level2_dead,individual,],)# Dropdowns Deadbutton_collision_dead.click(dropdown_collision,inputs=[individual],outputs=[dropdown_dead,dropdown_level2_dead,openfield_level2_dead,dropdown_extra_level2_dead,individual,],)button_deliberate_destruction_dead.click(dropdown_deliberate_destruction,inputs=[individual],outputs=[dropdown_dead,dropdown_level2_dead,openfield_level2_dead,dropdown_extra_level2_dead,individual,],)button_indirect_destruction_dead.click(dropdown_indirect_destruction,inputs=[individual],outputs=[dropdown_dead,dropdown_level2_dead,openfield_level2_dead,dropdown_extra_level2_dead,individual,],)button_natural_cause_dead.click(dropdown_natural_cause,inputs=[individual],outputs=[dropdown_dead,dropdown_level2_dead,openfield_level2_dead,dropdown_extra_level2_dead,individual,],)dropdown_dead.select(on_select,inputs=[individual],outputs=[dropdown_level2_dead,openfield_level2_dead,dropdown_extra_level2_dead,individual,],)dropdown_level2_dead.select(on_select_dropdown_level2, inputs=[individual], outputs=[individual])openfield_level2_dead.change(on_change_openfield_level2,inputs=[openfield_level2_dead, individual],outputs=[individual],)dropdown_extra_level2_dead.select(on_select_dropdown_extra_level2, inputs=[individual], outputs=[individual])# ---------------------------------------------------------# Radio Physical Deadradio_physical_dead.change(fn=show_physical,inputs=[radio_physical_dead, gr.Text("dead", visible=False), individual],outputs=[physical_boxes_dead, individual],)# Checkbox Physical Deadphysical_boxes_dead.select(find_bounding_box,inputs=[physical_boxes_dead, gr.Textbox(value="dead", visible=False)],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,],)checkbox_beak_dead.select(on_select_body_part,inputs=[checkbox_beak_dead, gr.Text("beak", visible=False), individual],outputs=[individual],)checkbox_body_dead.select(on_select_body_part,inputs=[checkbox_body_dead, gr.Text("body", visible=False), individual],outputs=[individual],)checkbox_feathers_dead.select(on_select_body_part,inputs=[checkbox_feathers_dead, gr.Text("feathers", visible=False), individual],outputs=[individual],)checkbox_head_dead.select(on_select_body_part,inputs=[checkbox_head_dead, gr.Text("head", visible=False), individual],outputs=[individual],)checkbox_legs_dead.select(on_select_body_part,inputs=[checkbox_legs_dead, gr.Text("legs", visible=False), individual],outputs=[individual],)# ---------------------------------------------------------# ---------------------------------------------------------# ---------------------------------------------------------1 unmodified line# WOUNDED# ---------------------------------------------------------# Radio Circumstance Woundedradio_circumstance_wounded.change(fn=show_circumstances,inputs=[radio_circumstance_wounded, individual],outputs=[button_collision_wounded,button_deliberate_destruction_wounded,button_indirect_destruction_wounded,button_natural_cause_wounded,dropdown_wounded,dropdown_level2_wounded,openfield_level2_wounded,dropdown_extra_level2_wounded,individual,],)# Dropdowns Circumstance Woundedbutton_collision_wounded.click(dropdown_collision,inputs=[individual],outputs=[dropdown_wounded,dropdown_level2_wounded,openfield_level2_wounded,dropdown_extra_level2_wounded,individual,],)button_deliberate_destruction_wounded.click(dropdown_deliberate_destruction,inputs=[individual],outputs=[dropdown_wounded,dropdown_level2_wounded,openfield_level2_wounded,dropdown_extra_level2_wounded,individual,],)button_indirect_destruction_wounded.click(dropdown_indirect_destruction,inputs=[individual],outputs=[dropdown_wounded,dropdown_level2_wounded,openfield_level2_wounded,dropdown_extra_level2_wounded,individual,],)button_natural_cause_wounded.click(dropdown_natural_cause,inputs=[individual],outputs=[dropdown_wounded,dropdown_level2_wounded,openfield_level2_wounded,dropdown_extra_level2_wounded,individual,],)dropdown_wounded.select(on_select,inputs=[individual],outputs=[dropdown_level2_wounded,openfield_level2_wounded,dropdown_extra_level2_wounded,individual,],)dropdown_level2_wounded.select(on_select_dropdown_level2, inputs=[individual], outputs=[individual])openfield_level2_wounded.change(on_change_openfield_level2, inputs=[openfield_level2_wounded, individual])dropdown_extra_level2_wounded.select(on_select_dropdown_extra_level2, inputs=[individual], outputs=[individual])# ---------------------------------------------------------# Radio Behavior Woundedradio_behavior_wounded.change(fn=show_behavior,inputs=[radio_behavior_wounded,gr.Text("wounded / sick", visible=False),gr.Text(mode, visible=False),individual,],outputs=[behavior_checkbox, behavior_text, individual],)behavior_checkbox.select(on_select_behavior, inputs=[behavior_checkbox, individual], outputs=[individual])# ---------------------------------------------------------# Radio Physical Woundedradio_physical_wounded.change(fn=show_physical,inputs=[radio_physical_wounded,gr.Text("wounded / sick", visible=False),individual,],outputs=[physical_boxes_wounded, individual],)# Checkbox Physical Woundedphysical_boxes_wounded.select(find_bounding_box,inputs=[physical_boxes_wounded,gr.Textbox(value="wounded / sick", visible=False),],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,],)checkbox_beak_wounded.select(on_select_body_part,inputs=[checkbox_beak_wounded, gr.Text("beak", visible=False), individual],outputs=[individual],)checkbox_body_wounded.select(on_select_body_part,inputs=[checkbox_body_wounded, gr.Text("body", visible=False), individual],outputs=[individual],)checkbox_feathers_wounded.select(on_select_body_part,inputs=[checkbox_feathers_wounded,gr.Text("feathers", visible=False),individual,],outputs=[individual],)checkbox_head_wounded.select(on_select_body_part,inputs=[checkbox_head_wounded, gr.Text("head", visible=False), individual],outputs=[individual],)checkbox_legs_wounded.select(on_select_body_part,inputs=[checkbox_legs_wounded, gr.Text("legs", visible=False), individual],outputs=[individual],)# ---------------------------------------------------------# Follow Up Events Woundedfe_collection_dropdown_wounded.select(save_fe,inputs=[fe_collection_dropdown_wounded,gr.Textbox("animal collected", visible=False),individual,],outputs=[individual],)fe_recepient_dropdown_wounded.select(save_fe,inputs=[fe_recepient_dropdown_wounded,gr.Textbox("recipient", visible=False),individual,],outputs=[individual],)fe_radio_dropdown_wounded.select(save_fe,inputs=[fe_radio_dropdown_wounded,gr.Textbox("radiography", visible=False),individual,],outputs=[individual],)fe_answer_dropdown_wounded.select(save_fe,inputs=[fe_answer_dropdown_wounded,gr.Textbox("given answer", visible=False),individual,],outputs=[individual],)fe_name_recipient_wounded.input(save_fe,inputs=[fe_name_recipient_wounded,gr.Textbox("recipient name", visible=False),individual,],outputs=[individual],)fe_collection_ref_wounded.input(save_fe,inputs=[fe_collection_ref_wounded,gr.Textbox("collection reference", visible=False),individual,],outputs=[individual],)# ---------------------------------------------------------# Follow Up Events Deadfe_collection_dropdown_dead.select(save_fe,inputs=[fe_collection_dropdown_dead,gr.Textbox("animal collected", visible=False),individual,],outputs=[individual],)fe_recepient_dropdown_dead.select(save_fe,inputs=[fe_recepient_dropdown_dead,gr.Textbox("recipient", visible=False),individual,],outputs=[individual],)fe_radio_dropdown_dead.select(save_fe,inputs=[fe_radio_dropdown_dead,gr.Textbox("radiography", visible=False),individual,],outputs=[individual],)fe_answer_dropdown_dead.select(save_fe,inputs=[fe_answer_dropdown_dead,gr.Textbox("given answer", visible=False),individual,],outputs=[individual],)fe_name_recipient_dead.input(save_fe,inputs=[fe_name_recipient_dead,gr.Textbox("recipient name", visible=False),individual,],outputs=[individual],)fe_collection_ref_dead.input(save_fe,inputs=[fe_collection_ref_dead,gr.Textbox("collection reference", visible=False),individual,],outputs=[individual],)# ---------------------------------------------------------# Spacerwith gr.Row(elem_id="centered-row"):gr.Image(PATH_ICONS + "animal.png",height=80,width=80,interactive=False,show_fullscreen_button=False,show_share_button=False,show_download_button=False,show_label=False,)advanced.css = """#centered-row {display: flex;justify-content: center;}"""# ---------------------------------------------------------# Error Boxwith gr.Row():error_icon = gr.Image(PATH_ICONS + "chicken.png", height=80, width=80, visible=False, scale=1)error_box = gr.Text(value=None, visible=False, scale=3)# ---------------------------------------------------------# Allow clearing of all previous outputwith gr.Row():button_df = gr.Button("SUBMIT OBSERVATION", icon=PATH_ICONS + "effective.png", scale=3)button_clear = gr.ClearButton(value="CLEAR",scale=1,components=[camera,location,identified_location,# dead resetradio_circumstance_dead,radio_physical_dead,button_collision_dead,button_deliberate_destruction_dead,button_indirect_destruction_dead,button_natural_cause_dead,dropdown_dead,dropdown_level2_dead,# openfield_level2_dead,dropdown_extra_level2_dead,physical_boxes_dead,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,fe_collection_dropdown_dead,fe_recepient_dropdown_dead,fe_radio_dropdown_dead,fe_answer_dropdown_dead,fe_name_recipient_dead,fe_collection_ref_dead,# wounded resetradio_circumstance_wounded,radio_behavior_wounded,radio_physical_wounded,button_collision_wounded,button_deliberate_destruction_wounded,button_indirect_destruction_wounded,button_natural_cause_wounded,dropdown_wounded,dropdown_level2_wounded,# openfield_level2_wounded,dropdown_extra_level2_wounded,behavior_checkbox,behavior_text,physical_boxes_wounded,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,fe_collection_dropdown_wounded,fe_recepient_dropdown_wounded,fe_radio_dropdown_wounded,fe_answer_dropdown_wounded,fe_name_recipient_wounded,fe_collection_ref_wounded,error_icon,error_box,],)# ---------------------------------------------------------# VALIDATE ANIMALbutton_df.click(validate_save_individual,inputs=[individual, error_icon, error_box, gr.Text(mode, visible=False)],outputs=[error_icon, error_box],)# ---------------------------------------------------------# CLEAR BUTTONbutton_clear.click()button_clear.click(hide_physical,inputs=[gr.Text(mode, visible=False)],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,],)button_clear.click(hide_physical,inputs=[gr.Text(mode, visible=False)],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,],)button_clear.click(reset_error_box, inputs=[error_icon, error_box], outputs=[error_icon, error_box])button_clear.click(reset_individual, inputs=[individual], outputs=[individual])
13 unmodified lines1415161718192021222324252627282930313233343536373839404142434445464748495051521 unmodified line5455565758596061626364653 unmodified lines697071727374757677787980818283842 unmodified lines878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241252 unmodified lines1281291301311321331341351361371381391401411421431441451461471481491501511 unmodified line1531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202211 unmodified line2232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692701 unmodified line27227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943013 unmodified linesfrom styling.style import *from validation_submission.submission import validate_save_individualfrom validation_submission.utils_save import save_details, save_imagefrom validation_submission.resets import reset_individual, reset_error_box, hide_physicalfrom dotenv import load_dotenvimport osload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv('PATH_ASSETS')PATH_ICONS = PATH + PATH_ASSETS + "icons/"with gr.Blocks(theme='shivi/calm_seafoam') as simple:mode = "simple"individual = gr.State({})# ---------------------------------------------------------# Header Textwith gr.Row():gr.Image(PATH_ICONS+"swallow.png", scale =0.1,interactive=False,show_fullscreen_button = False, show_share_button=False,show_download_button=False, show_label=False)with gr.Column(scale=1):title = gr.Markdown("# Welcome to Digiwild", label="Title")description = gr.Markdown("## Please record your wildlife observations here !", label="description")# ---------------------------------------------------------# Camerawith gr.Row():camera = gr.Image(elem_id="image")camera.input(save_image, inputs=[camera, individual], outputs=[individual])# ---------------------------------------------------------# General Detailswith gr.Column(scale=1):gr.Button("General Details", icon=PATH_ICONS+"pigeon.png", variant="primary")with gr.Row():specie = gr.Textbox(1 unmodified lineplaceholder="e.g. European Robin, Common Blackbird",info="Enter the species name if you can identify it. If unsure, provide your best guess or general description (e.g. 'small brown bird')",visible=True,interactive=True)specie.change(save_details,inputs=[gr.Textbox("specie", visible=False),specie],outputs=individual)# Number of individualswith gr.Row():3 unmodified linesminimum=1,precision=0, # Only whole numbersinfo="Enter the number of animals observed",#placeholder="Enter number...",visible=True,interactive=True)num_individuals.change(save_details,inputs=[gr.Textbox("number", visible=False),num_individuals],outputs=individual)# Introducing text_box for commentswith gr.Row():comments = gr.TextArea(label="Additional Comments",2 unmodified lineslines=3,max_lines=5,visible=True,interactive=True)comments.change(save_details,inputs=[gr.Textbox("comments", visible=False),comments],outputs=individual)with gr.Row():with gr.Column(scale=1):# Geolocationgr.Button("Location", icon=PATH_ICONS+"pin.png", variant="primary")location_data = gr.JSON(label="Identified GPS Location", visible=False)hidden_input = gr.Textbox(visible=False, elem_id="textbox_id")locationtext = gr.Textbox(visible=False, elem_id="textbox_id")btn_gpslocation = gr.Button("Get Coordinates using GPS (Permission required - May take a few seconds)")btn_gpslocation.click(None, [], [], js=js_geocode)hidden_input.change(display_location,inputs=[hidden_input, individual],outputs=[locationtext, individual])# ---------------------------------------------------------# Dead and Wounded Buttonsgr.Button("State of the Animal", variant="primary")with gr.Row():gr.Image(PATH_ICONS+"medical-app.png", scale =0.1,interactive=False,show_fullscreen_button = False, show_share_button=False,show_download_button=False, show_label=False)with gr.Column():gr.Markdown("## The State of the Animal", label="Title")gr.Markdown("Please tell us if the animal was wounded / sick or dead.", label="description")gr.Markdown("Please fill out as many fields as you can, based on what you can see.", label="description")gr.Markdown("### DO NOT TOUCH the animal unless absolutely necessary.", label="description")with gr.Row() as block_form:with gr.Column(scale=1):butt_wounded = gr.Button("Wounded / Sick", elem_id="wounded")2 unmodified lines# ---------------------------------------------------------# Initiate sectionssection_dead, individual, radio_circumstance_dead, radio_physical_dead,\button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead, \dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \physical_boxes_dead, \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, \fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \fe_name_recipient_dead, fe_collection_ref_dead \= show_section_dead(False, mode, individual)section_wounded, individual, radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded, \button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded, \dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, \behavior_checkbox, behavior_text, \physical_boxes_wounded, \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, \fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \fe_name_recipient_wounded, fe_collection_ref_wounded \= show_section_wounded(False, mode, individual)# ---------------------------------------------------------# ---------------------------------------------------------1 unmodified line# Dead Button Logicpartial_show_section_dead = partial(show_section_dead, True)partial_hide_section_wounded = partial(show_section_wounded, False)butt_dead.click(partial_show_section_dead,inputs=[gr.Text(mode, visible=False),individual],outputs=[section_dead,individual,radio_circumstance_dead, radio_physical_dead,button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \physical_boxes_dead, \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, \fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \fe_name_recipient_dead, fe_collection_ref_dead \])butt_dead.click(partial_hide_section_wounded,inputs=[gr.Text(mode, visible=False),individual],outputs=[section_wounded,individual,radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,behavior_checkbox, behavior_text,physical_boxes_wounded, \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, \fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \fe_name_recipient_wounded, fe_collection_ref_wounded \])# ---------------------------------------------------------# Wounded Button Logicpartial_show_section_wounded = partial(show_section_wounded, True)partial_hide_section_dead = partial(show_section_dead, False)butt_wounded.click(partial_show_section_wounded,inputs=[gr.Text(mode, visible=False),individual],outputs=[section_wounded,individual,radio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded,behavior_checkbox, behavior_text,physical_boxes_wounded, \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, \fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded, \fe_name_recipient_wounded, fe_collection_ref_wounded \])butt_wounded.click(partial_hide_section_dead,inputs=[gr.Text(mode, visible=False),individual],outputs=[section_dead,individual,radio_circumstance_dead, radio_physical_dead,button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, \physical_boxes_dead, \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, \fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead, \fe_name_recipient_dead, fe_collection_ref_dead \])# ---------------------------------------------------------# ---------------------------------------------------------# ---------------------------------------------------------1 unmodified line# DEAD# ---------------------------------------------------------# Radio Circumstance Deadradio_circumstance_dead.change(fn=show_circumstances,inputs=[radio_circumstance_dead, individual],outputs=[button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])# Dropdowns Deadbutton_collision_dead.click(dropdown_collision,inputs=[individual],outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])button_deliberate_destruction_dead.click(dropdown_deliberate_destruction, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])button_indirect_destruction_dead.click(dropdown_indirect_destruction, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])button_natural_cause_dead.click(dropdown_natural_cause, inputs=[individual], outputs=[dropdown_dead, dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])dropdown_dead.select(on_select, inputs=[individual], outputs=[dropdown_level2_dead, openfield_level2_dead, dropdown_extra_level2_dead, individual])dropdown_level2_dead.select(on_select_dropdown_level2, inputs=[individual], outputs=[individual] )openfield_level2_dead.change(on_change_openfield_level2, inputs=[openfield_level2_dead, individual], outputs=[individual])dropdown_extra_level2_dead.select(on_select_dropdown_extra_level2, inputs=[individual], outputs=[individual])# ---------------------------------------------------------# Radio Physical Deadradio_physical_dead.change(fn=show_physical,inputs=[radio_physical_dead,gr.Text("dead", visible=False),individual],outputs=[physical_boxes_dead, individual])# Checkbox Physical Deadphysical_boxes_dead.select(find_bounding_box,inputs=[physical_boxes_dead,gr.Textbox(value="dead", visible=False),gr.Text(mode, visible=False)],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])checkbox_beak_dead.select(on_select_body_part, inputs=[checkbox_beak_dead, gr.Text("beak", visible=False), individual], outputs=[individual])checkbox_body_dead.select(on_select_body_part, inputs=[checkbox_body_dead, gr.Text("body", visible=False), individual], outputs=[individual])checkbox_feathers_dead.select(on_select_body_part, inputs=[checkbox_feathers_dead, gr.Text("feathers", visible=False), individual], outputs=[individual])checkbox_head_dead.select(on_select_body_part, inputs=[checkbox_head_dead, gr.Text("head", visible=False), individual], outputs=[individual])checkbox_legs_dead.select(on_select_body_part, inputs=[checkbox_legs_dead, gr.Text("legs", visible=False), individual], outputs=[individual])# ---------------------------------------------------------# ---------------------------------------------------------# ---------------------------------------------------------1 unmodified line# WOUNDED# ---------------------------------------------------------# Radio Circumstance Woundedradio_circumstance_wounded.change(fn=show_circumstances,inputs=[radio_circumstance_wounded, individual],outputs=[button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])# Dropdowns Circumstance Woundedbutton_collision_wounded.click(dropdown_collision,inputs=[individual],outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])button_deliberate_destruction_wounded.click(dropdown_deliberate_destruction, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])button_indirect_destruction_wounded.click(dropdown_indirect_destruction, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])button_natural_cause_wounded.click(dropdown_natural_cause, inputs=[individual], outputs=[dropdown_wounded, dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])dropdown_wounded.select(on_select, inputs=[individual], outputs=[dropdown_level2_wounded, openfield_level2_wounded, dropdown_extra_level2_wounded, individual])dropdown_level2_wounded.select(on_select_dropdown_level2, inputs=[individual], outputs=[individual])openfield_level2_wounded.change(on_change_openfield_level2, inputs=[openfield_level2_wounded, individual])dropdown_extra_level2_wounded.select(on_select_dropdown_extra_level2, inputs=[individual], outputs=[individual])# ---------------------------------------------------------# Radio Behavior Woundedradio_behavior_wounded.change(fn=show_behavior,inputs=[radio_behavior_wounded,gr.Text("wounded / sick", visible=False),gr.Text(mode, visible=False),individual],outputs=[behavior_checkbox, behavior_text, individual])behavior_checkbox.select(on_select_behavior,inputs=[behavior_checkbox, individual],outputs=[individual])# ---------------------------------------------------------# Radio Physical Woundedradio_physical_wounded.change(fn=show_physical,inputs=[radio_physical_wounded,gr.Text("wounded / sick", visible=False),individual],outputs=[physical_boxes_wounded, individual])# Checkbox Physical Woundedphysical_boxes_wounded.select(find_bounding_box,inputs=[physical_boxes_wounded,gr.Textbox(value="wounded / sick", visible=False),gr.Text(mode, visible=False)],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])checkbox_beak_wounded.select(on_select_body_part, inputs=[checkbox_beak_wounded, gr.Text("beak", visible=False), individual], outputs=[individual])checkbox_body_wounded.select(on_select_body_part, inputs=[checkbox_body_wounded, gr.Text("body", visible=False), individual], outputs=[individual])checkbox_feathers_wounded.select(on_select_body_part, inputs=[checkbox_feathers_wounded, gr.Text("feathers", visible=False), individual], outputs=[individual])checkbox_head_wounded.select(on_select_body_part, inputs=[checkbox_head_wounded, gr.Text("head", visible=False), individual], outputs=[individual])checkbox_legs_wounded.select(on_select_body_part, inputs=[checkbox_legs_wounded, gr.Text("legs", visible=False), individual], outputs=[individual])# ---------------------------------------------------------# Follow Up Events Woundedfe_collection_dropdown_wounded.select(save_fe, inputs=[fe_collection_dropdown_wounded, gr.Textbox("animal collected", visible=False), individual], outputs=[individual])fe_recepient_dropdown_wounded.select(save_fe, inputs=[fe_recepient_dropdown_wounded, gr.Textbox("recipient", visible=False), individual],outputs=[individual])fe_radio_dropdown_wounded.select(save_fe, inputs=[fe_radio_dropdown_wounded, gr.Textbox("radiography", visible=False), individual],outputs=[individual])fe_answer_dropdown_wounded.select(save_fe, inputs=[fe_answer_dropdown_wounded, gr.Textbox("given answer", visible=False), individual],outputs=[individual])fe_name_recipient_wounded.input(save_fe, inputs=[fe_name_recipient_wounded, gr.Textbox("recipient name", visible=False), individual],outputs=[individual])fe_collection_ref_wounded.input(save_fe, inputs=[fe_collection_ref_wounded, gr.Textbox("collection reference", visible=False), individual],outputs=[individual])# ---------------------------------------------------------# Follow Up Events Deadfe_collection_dropdown_dead.select(save_fe, inputs=[fe_collection_dropdown_dead, gr.Textbox("animal collected", visible=False), individual],outputs=[individual])fe_recepient_dropdown_dead.select(save_fe, inputs=[fe_recepient_dropdown_dead, gr.Textbox("recipient", visible=False), individual],outputs=[individual])fe_radio_dropdown_dead.select(save_fe, inputs=[fe_radio_dropdown_dead, gr.Textbox("radiography", visible=False), individual],outputs=[individual])fe_answer_dropdown_dead.select(save_fe, inputs=[fe_answer_dropdown_dead, gr.Textbox("given answer", visible=False), individual],outputs=[individual])fe_name_recipient_dead.input(save_fe, inputs=[fe_name_recipient_dead, gr.Textbox("recipient name", visible=False), individual],outputs=[individual])fe_collection_ref_dead.input(save_fe, inputs=[fe_collection_ref_dead, gr.Textbox("collection reference", visible=False), individual], outputs=[individual])# ---------------------------------------------------------# Spacerwith gr.Row(elem_id="centered-row"):gr.Image(PATH_ICONS+"chicken.png", height=80, width=80,interactive=False,show_fullscreen_button = False, show_share_button=False,show_download_button=False, show_label=False)simple.css = """#centered-row {display: flex;justify-content: center;}"""# ---------------------------------------------------------# Error Boxwith gr.Row():error_icon = gr.Image(PATH_ICONS+"chicken.png", height=80, width=80, visible=False, scale=1)error_box = gr.Text(value=None, visible=False, scale=4)# ---------------------------------------------------------# Allow clearing of all previous outputwith gr.Row():button_df = gr.Button("SUBMIT OBSERVATION", icon=PATH_ICONS+"effective.png",scale = 3)button_clear = gr.ClearButton(value="CLEAR / Create NEW Observation",scale = 2,icon = PATH_ICONS+"balai-magique.png",components=[camera,#dead resetradio_circumstance_dead, radio_physical_dead,button_collision_dead, button_deliberate_destruction_dead, button_indirect_destruction_dead, button_natural_cause_dead,dropdown_dead, dropdown_level2_dead,#openfield_level2_dead,dropdown_extra_level2_dead,physical_boxes_dead,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,fe_collection_dropdown_dead, fe_recepient_dropdown_dead, fe_radio_dropdown_dead, fe_answer_dropdown_dead,fe_name_recipient_dead, fe_collection_ref_dead,#wounded resetradio_circumstance_wounded, radio_behavior_wounded, radio_physical_wounded,button_collision_wounded, button_deliberate_destruction_wounded, button_indirect_destruction_wounded, button_natural_cause_wounded,dropdown_wounded, dropdown_level2_wounded,#openfield_level2_wounded,dropdown_extra_level2_wounded,behavior_checkbox, behavior_text,physical_boxes_wounded,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,fe_collection_dropdown_wounded, fe_recepient_dropdown_wounded, fe_radio_dropdown_wounded, fe_answer_dropdown_wounded,fe_name_recipient_wounded, fe_collection_ref_wounded,error_icon, error_box])# ---------------------------------------------------------# VALIDATE & SUBMIT ANIMALbutton_df.click(validate_save_individual,inputs=[individual,error_icon,error_box,gr.Text(mode, visible=False)],outputs=[error_icon, error_box])# ---------------------------------------------------------# CLEAR BUTTONbutton_clear.click()button_clear.click(hide_physical,inputs=[gr.Text(mode, visible=False)],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])button_clear.click(hide_physical,inputs=[gr.Text(mode, visible=False)],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])button_clear.click(reset_error_box, inputs=[error_icon, error_box], outputs=[error_icon, error_box])button_clear.click(reset_individual, inputs=[individual], outputs=[individual])13 unmodified lines1415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566671 unmodified line697071727374757677787980813 unmodified lines8586878889909192939495969798991001012 unmodified lines1041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641652 unmodified lines1681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382391 unmodified line2412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004011 unmodified line4034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445451 unmodified line54754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297313 unmodified linesfrom styling.style import *from validation_submission.submission import validate_save_individualfrom validation_submission.utils_save import save_details, save_imagefrom validation_submission.resets import (reset_individual,reset_error_box,hide_physical,)from dotenv import load_dotenvimport osload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv("PATH_ASSETS")PATH_ICONS = PATH + PATH_ASSETS + "icons/"with gr.Blocks(theme="shivi/calm_seafoam") as simple:mode = "simple"individual = gr.State({})# ---------------------------------------------------------# Header Textwith gr.Row():gr.Image(PATH_ICONS + "swallow.png",scale=0.1,interactive=False,show_fullscreen_button=False,show_share_button=False,show_download_button=False,show_label=False,)with gr.Column(scale=1):title = gr.Markdown("# Welcome to Digiwild", label="Title")description = gr.Markdown("## Please record your wildlife observations here !",label="description",)# ---------------------------------------------------------# Camerawith gr.Row():camera = gr.Image(elem_id="image")camera.input(save_image, inputs=[camera, individual], outputs=[individual])# ---------------------------------------------------------# General Detailswith gr.Column(scale=1):gr.Button("General Details", icon=PATH_ICONS + "pigeon.png", variant="primary")with gr.Row():specie = gr.Textbox(1 unmodified lineplaceholder="e.g. European Robin, Common Blackbird",info="Enter the species name if you can identify it. If unsure, provide your best guess or general description (e.g. 'small brown bird')",visible=True,interactive=True,)specie.change(save_details,inputs=[gr.Textbox("specie", visible=False), specie],outputs=individual,)# Number of individualswith gr.Row():3 unmodified linesminimum=1,precision=0, # Only whole numbersinfo="Enter the number of animals observed",# placeholder="Enter number...",visible=True,interactive=True,)num_individuals.change(save_details,inputs=[gr.Textbox("number", visible=False), num_individuals],outputs=individual,)# Introducing text_box for commentswith gr.Row():comments = gr.TextArea(label="Additional Comments",2 unmodified lineslines=3,max_lines=5,visible=True,interactive=True,)comments.change(save_details,inputs=[gr.Textbox("comments", visible=False), comments],outputs=individual,)with gr.Row():with gr.Column(scale=1):# Geolocationgr.Button("Location", icon=PATH_ICONS + "pin.png", variant="primary")location_data = gr.JSON(label="Identified GPS Location", visible=False)hidden_input = gr.Textbox(visible=False, elem_id="textbox_id")locationtext = gr.Textbox(visible=False, elem_id="textbox_id")btn_gpslocation = gr.Button("Get Coordinates using GPS (Permission required - May take a few seconds)")btn_gpslocation.click(None, [], [], js=js_geocode)hidden_input.change(display_location,inputs=[hidden_input, individual],outputs=[locationtext, individual],)# ---------------------------------------------------------# Dead and Wounded Buttonsgr.Button("State of the Animal", variant="primary")with gr.Row():gr.Image(PATH_ICONS + "medical-app.png",scale=0.1,interactive=False,show_fullscreen_button=False,show_share_button=False,show_download_button=False,show_label=False,)with gr.Column():gr.Markdown("## The State of the Animal", label="Title")gr.Markdown("Please tell us if the animal was wounded / sick or dead.",label="description",)gr.Markdown("Please fill out as many fields as you can, based on what you can see.",label="description",)gr.Markdown("### DO NOT TOUCH the animal unless absolutely necessary.",label="description",)with gr.Row() as block_form:with gr.Column(scale=1):butt_wounded = gr.Button("Wounded / Sick", elem_id="wounded")2 unmodified lines# ---------------------------------------------------------# Initiate sections(section_dead,individual,radio_circumstance_dead,radio_physical_dead,button_collision_dead,button_deliberate_destruction_dead,button_indirect_destruction_dead,button_natural_cause_dead,dropdown_dead,dropdown_level2_dead,openfield_level2_dead,dropdown_extra_level2_dead,physical_boxes_dead,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,fe_collection_dropdown_dead,fe_recepient_dropdown_dead,fe_radio_dropdown_dead,fe_answer_dropdown_dead,fe_name_recipient_dead,fe_collection_ref_dead,) = show_section_dead(False, mode, individual)(section_wounded,individual,radio_circumstance_wounded,radio_behavior_wounded,radio_physical_wounded,button_collision_wounded,button_deliberate_destruction_wounded,button_indirect_destruction_wounded,button_natural_cause_wounded,dropdown_wounded,dropdown_level2_wounded,openfield_level2_wounded,dropdown_extra_level2_wounded,behavior_checkbox,behavior_text,physical_boxes_wounded,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,fe_collection_dropdown_wounded,fe_recepient_dropdown_wounded,fe_radio_dropdown_wounded,fe_answer_dropdown_wounded,fe_name_recipient_wounded,fe_collection_ref_wounded,) = show_section_wounded(False, mode, individual)# ---------------------------------------------------------# ---------------------------------------------------------1 unmodified line# Dead Button Logicpartial_show_section_dead = partial(show_section_dead, True)partial_hide_section_wounded = partial(show_section_wounded, False)butt_dead.click(partial_show_section_dead,inputs=[gr.Text(mode, visible=False), individual],outputs=[section_dead,individual,radio_circumstance_dead,radio_physical_dead,button_collision_dead,button_deliberate_destruction_dead,button_indirect_destruction_dead,button_natural_cause_dead,dropdown_dead,dropdown_level2_dead,openfield_level2_dead,dropdown_extra_level2_dead,physical_boxes_dead,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,fe_collection_dropdown_dead,fe_recepient_dropdown_dead,fe_radio_dropdown_dead,fe_answer_dropdown_dead,fe_name_recipient_dead,fe_collection_ref_dead,],)butt_dead.click(partial_hide_section_wounded,inputs=[gr.Text(mode, visible=False), individual],outputs=[section_wounded,individual,radio_circumstance_wounded,radio_behavior_wounded,radio_physical_wounded,button_collision_wounded,button_deliberate_destruction_wounded,button_indirect_destruction_wounded,button_natural_cause_wounded,dropdown_wounded,dropdown_level2_wounded,openfield_level2_wounded,dropdown_extra_level2_wounded,behavior_checkbox,behavior_text,physical_boxes_wounded,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,fe_collection_dropdown_wounded,fe_recepient_dropdown_wounded,fe_radio_dropdown_wounded,fe_answer_dropdown_wounded,fe_name_recipient_wounded,fe_collection_ref_wounded,],)# ---------------------------------------------------------# Wounded Button Logicpartial_show_section_wounded = partial(show_section_wounded, True)partial_hide_section_dead = partial(show_section_dead, False)butt_wounded.click(partial_show_section_wounded,inputs=[gr.Text(mode, visible=False), individual],outputs=[section_wounded,individual,radio_circumstance_wounded,radio_behavior_wounded,radio_physical_wounded,button_collision_wounded,button_deliberate_destruction_wounded,button_indirect_destruction_wounded,button_natural_cause_wounded,dropdown_wounded,dropdown_level2_wounded,openfield_level2_wounded,dropdown_extra_level2_wounded,behavior_checkbox,behavior_text,physical_boxes_wounded,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,fe_collection_dropdown_wounded,fe_recepient_dropdown_wounded,fe_radio_dropdown_wounded,fe_answer_dropdown_wounded,fe_name_recipient_wounded,fe_collection_ref_wounded,],)butt_wounded.click(partial_hide_section_dead,inputs=[gr.Text(mode, visible=False), individual],outputs=[section_dead,individual,radio_circumstance_dead,radio_physical_dead,button_collision_dead,button_deliberate_destruction_dead,button_indirect_destruction_dead,button_natural_cause_dead,dropdown_dead,dropdown_level2_dead,openfield_level2_dead,dropdown_extra_level2_dead,physical_boxes_dead,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,fe_collection_dropdown_dead,fe_recepient_dropdown_dead,fe_radio_dropdown_dead,fe_answer_dropdown_dead,fe_name_recipient_dead,fe_collection_ref_dead,],)# ---------------------------------------------------------# ---------------------------------------------------------# ---------------------------------------------------------1 unmodified line# DEAD# ---------------------------------------------------------# Radio Circumstance Deadradio_circumstance_dead.change(fn=show_circumstances,inputs=[radio_circumstance_dead, individual],outputs=[button_collision_dead,button_deliberate_destruction_dead,button_indirect_destruction_dead,button_natural_cause_dead,dropdown_dead,dropdown_level2_dead,openfield_level2_dead,dropdown_extra_level2_dead,individual,],)# Dropdowns Deadbutton_collision_dead.click(dropdown_collision,inputs=[individual],outputs=[dropdown_dead,dropdown_level2_dead,openfield_level2_dead,dropdown_extra_level2_dead,individual,],)button_deliberate_destruction_dead.click(dropdown_deliberate_destruction,inputs=[individual],outputs=[dropdown_dead,dropdown_level2_dead,openfield_level2_dead,dropdown_extra_level2_dead,individual,],)button_indirect_destruction_dead.click(dropdown_indirect_destruction,inputs=[individual],outputs=[dropdown_dead,dropdown_level2_dead,openfield_level2_dead,dropdown_extra_level2_dead,individual,],)button_natural_cause_dead.click(dropdown_natural_cause,inputs=[individual],outputs=[dropdown_dead,dropdown_level2_dead,openfield_level2_dead,dropdown_extra_level2_dead,individual,],)dropdown_dead.select(on_select,inputs=[individual],outputs=[dropdown_level2_dead,openfield_level2_dead,dropdown_extra_level2_dead,individual,],)dropdown_level2_dead.select(on_select_dropdown_level2, inputs=[individual], outputs=[individual])openfield_level2_dead.change(on_change_openfield_level2,inputs=[openfield_level2_dead, individual],outputs=[individual],)dropdown_extra_level2_dead.select(on_select_dropdown_extra_level2, inputs=[individual], outputs=[individual])# ---------------------------------------------------------# Radio Physical Deadradio_physical_dead.change(fn=show_physical,inputs=[radio_physical_dead, gr.Text("dead", visible=False), individual],outputs=[physical_boxes_dead, individual],)# Checkbox Physical Deadphysical_boxes_dead.select(find_bounding_box,inputs=[physical_boxes_dead,gr.Textbox(value="dead", visible=False),gr.Text(mode, visible=False),],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,],)checkbox_beak_dead.select(on_select_body_part,inputs=[checkbox_beak_dead, gr.Text("beak", visible=False), individual],outputs=[individual],)checkbox_body_dead.select(on_select_body_part,inputs=[checkbox_body_dead, gr.Text("body", visible=False), individual],outputs=[individual],)checkbox_feathers_dead.select(on_select_body_part,inputs=[checkbox_feathers_dead, gr.Text("feathers", visible=False), individual],outputs=[individual],)checkbox_head_dead.select(on_select_body_part,inputs=[checkbox_head_dead, gr.Text("head", visible=False), individual],outputs=[individual],)checkbox_legs_dead.select(on_select_body_part,inputs=[checkbox_legs_dead, gr.Text("legs", visible=False), individual],outputs=[individual],)# ---------------------------------------------------------# ---------------------------------------------------------# ---------------------------------------------------------1 unmodified line# WOUNDED# ---------------------------------------------------------# Radio Circumstance Woundedradio_circumstance_wounded.change(fn=show_circumstances,inputs=[radio_circumstance_wounded, individual],outputs=[button_collision_wounded,button_deliberate_destruction_wounded,button_indirect_destruction_wounded,button_natural_cause_wounded,dropdown_wounded,dropdown_level2_wounded,openfield_level2_wounded,dropdown_extra_level2_wounded,individual,],)# Dropdowns Circumstance Woundedbutton_collision_wounded.click(dropdown_collision,inputs=[individual],outputs=[dropdown_wounded,dropdown_level2_wounded,openfield_level2_wounded,dropdown_extra_level2_wounded,individual,],)button_deliberate_destruction_wounded.click(dropdown_deliberate_destruction,inputs=[individual],outputs=[dropdown_wounded,dropdown_level2_wounded,openfield_level2_wounded,dropdown_extra_level2_wounded,individual,],)button_indirect_destruction_wounded.click(dropdown_indirect_destruction,inputs=[individual],outputs=[dropdown_wounded,dropdown_level2_wounded,openfield_level2_wounded,dropdown_extra_level2_wounded,individual,],)button_natural_cause_wounded.click(dropdown_natural_cause,inputs=[individual],outputs=[dropdown_wounded,dropdown_level2_wounded,openfield_level2_wounded,dropdown_extra_level2_wounded,individual,],)dropdown_wounded.select(on_select,inputs=[individual],outputs=[dropdown_level2_wounded,openfield_level2_wounded,dropdown_extra_level2_wounded,individual,],)dropdown_level2_wounded.select(on_select_dropdown_level2, inputs=[individual], outputs=[individual])openfield_level2_wounded.change(on_change_openfield_level2, inputs=[openfield_level2_wounded, individual])dropdown_extra_level2_wounded.select(on_select_dropdown_extra_level2, inputs=[individual], outputs=[individual])# ---------------------------------------------------------# Radio Behavior Woundedradio_behavior_wounded.change(fn=show_behavior,inputs=[radio_behavior_wounded,gr.Text("wounded / sick", visible=False),gr.Text(mode, visible=False),individual,],outputs=[behavior_checkbox, behavior_text, individual],)behavior_checkbox.select(on_select_behavior, inputs=[behavior_checkbox, individual], outputs=[individual])# ---------------------------------------------------------# Radio Physical Woundedradio_physical_wounded.change(fn=show_physical,inputs=[radio_physical_wounded,gr.Text("wounded / sick", visible=False),individual,],outputs=[physical_boxes_wounded, individual],)# Checkbox Physical Woundedphysical_boxes_wounded.select(find_bounding_box,inputs=[physical_boxes_wounded,gr.Textbox(value="wounded / sick", visible=False),gr.Text(mode, visible=False),],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,],)checkbox_beak_wounded.select(on_select_body_part,inputs=[checkbox_beak_wounded, gr.Text("beak", visible=False), individual],outputs=[individual],)checkbox_body_wounded.select(on_select_body_part,inputs=[checkbox_body_wounded, gr.Text("body", visible=False), individual],outputs=[individual],)checkbox_feathers_wounded.select(on_select_body_part,inputs=[checkbox_feathers_wounded,gr.Text("feathers", visible=False),individual,],outputs=[individual],)checkbox_head_wounded.select(on_select_body_part,inputs=[checkbox_head_wounded, gr.Text("head", visible=False), individual],outputs=[individual],)checkbox_legs_wounded.select(on_select_body_part,inputs=[checkbox_legs_wounded, gr.Text("legs", visible=False), individual],outputs=[individual],)# ---------------------------------------------------------# Follow Up Events Woundedfe_collection_dropdown_wounded.select(save_fe,inputs=[fe_collection_dropdown_wounded,gr.Textbox("animal collected", visible=False),individual,],outputs=[individual],)fe_recepient_dropdown_wounded.select(save_fe,inputs=[fe_recepient_dropdown_wounded,gr.Textbox("recipient", visible=False),individual,],outputs=[individual],)fe_radio_dropdown_wounded.select(save_fe,inputs=[fe_radio_dropdown_wounded,gr.Textbox("radiography", visible=False),individual,],outputs=[individual],)fe_answer_dropdown_wounded.select(save_fe,inputs=[fe_answer_dropdown_wounded,gr.Textbox("given answer", visible=False),individual,],outputs=[individual],)fe_name_recipient_wounded.input(save_fe,inputs=[fe_name_recipient_wounded,gr.Textbox("recipient name", visible=False),individual,],outputs=[individual],)fe_collection_ref_wounded.input(save_fe,inputs=[fe_collection_ref_wounded,gr.Textbox("collection reference", visible=False),individual,],outputs=[individual],)# ---------------------------------------------------------# Follow Up Events Deadfe_collection_dropdown_dead.select(save_fe,inputs=[fe_collection_dropdown_dead,gr.Textbox("animal collected", visible=False),individual,],outputs=[individual],)fe_recepient_dropdown_dead.select(save_fe,inputs=[fe_recepient_dropdown_dead,gr.Textbox("recipient", visible=False),individual,],outputs=[individual],)fe_radio_dropdown_dead.select(save_fe,inputs=[fe_radio_dropdown_dead,gr.Textbox("radiography", visible=False),individual,],outputs=[individual],)fe_answer_dropdown_dead.select(save_fe,inputs=[fe_answer_dropdown_dead,gr.Textbox("given answer", visible=False),individual,],outputs=[individual],)fe_name_recipient_dead.input(save_fe,inputs=[fe_name_recipient_dead,gr.Textbox("recipient name", visible=False),individual,],outputs=[individual],)fe_collection_ref_dead.input(save_fe,inputs=[fe_collection_ref_dead,gr.Textbox("collection reference", visible=False),individual,],outputs=[individual],)# ---------------------------------------------------------# Spacerwith gr.Row(elem_id="centered-row"):gr.Image(PATH_ICONS + "chicken.png",height=80,width=80,interactive=False,show_fullscreen_button=False,show_share_button=False,show_download_button=False,show_label=False,)simple.css = """#centered-row {display: flex;justify-content: center;}"""# ---------------------------------------------------------# Error Boxwith gr.Row():error_icon = gr.Image(PATH_ICONS + "chicken.png", height=80, width=80, visible=False, scale=1)error_box = gr.Text(value=None, visible=False, scale=4)# ---------------------------------------------------------# Allow clearing of all previous outputwith gr.Row():button_df = gr.Button("SUBMIT OBSERVATION", icon=PATH_ICONS + "effective.png", scale=3)button_clear = gr.ClearButton(value="CLEAR / Create NEW Observation",scale=2,icon=PATH_ICONS + "balai-magique.png",components=[camera,# dead resetradio_circumstance_dead,radio_physical_dead,button_collision_dead,button_deliberate_destruction_dead,button_indirect_destruction_dead,button_natural_cause_dead,dropdown_dead,dropdown_level2_dead,# openfield_level2_dead,dropdown_extra_level2_dead,physical_boxes_dead,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,fe_collection_dropdown_dead,fe_recepient_dropdown_dead,fe_radio_dropdown_dead,fe_answer_dropdown_dead,fe_name_recipient_dead,fe_collection_ref_dead,# wounded resetradio_circumstance_wounded,radio_behavior_wounded,radio_physical_wounded,button_collision_wounded,button_deliberate_destruction_wounded,button_indirect_destruction_wounded,button_natural_cause_wounded,dropdown_wounded,dropdown_level2_wounded,# openfield_level2_wounded,dropdown_extra_level2_wounded,behavior_checkbox,behavior_text,physical_boxes_wounded,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,fe_collection_dropdown_wounded,fe_recepient_dropdown_wounded,fe_radio_dropdown_wounded,fe_answer_dropdown_wounded,fe_name_recipient_wounded,fe_collection_ref_wounded,error_icon,error_box,],)# ---------------------------------------------------------# VALIDATE & SUBMIT ANIMALbutton_df.click(validate_save_individual,inputs=[individual, error_icon, error_box, gr.Text(mode, visible=False)],outputs=[error_icon, error_box],)# ---------------------------------------------------------# CLEAR BUTTONbutton_clear.click()button_clear.click(hide_physical,inputs=[gr.Text(mode, visible=False)],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,],)button_clear.click(hide_physical,inputs=[gr.Text(mode, visible=False)],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,],)button_clear.click(reset_error_box, inputs=[error_icon, error_box], outputs=[error_icon, error_box])button_clear.click(reset_individual, inputs=[individual], outputs=[individual])
2 unmodified lines34567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677782 unmodified lines# Define common anomalies as a Literal typeCommonAnomalies = Literal['blackened/burnt skin','blood','foreign body','fracture','injury','parasite','swelling','warty or tumor-like growth, crusts']# --- Beak-related Anomalies ---class BeakAnomaly(BaseModel):type: Literal['beak']anomaly_type: List[Literal['adhesion','deformation',CommonAnomalies]]# --- Body-related Anomalies ---class BodyAnomaly(BaseModel):type: Literal['body']anomaly_type: List[Literal['emaciation','fluffed up','stained feathers',CommonAnomalies]]# --- Legs-related Anomalies ---class LegAnomaly(BaseModel):type: Literal['legs']anomaly_type: List[Literal['missing limb','deformation',CommonAnomalies]]# --- Feathers/Wings/Tail-related Anomalies ---class FeathersWingsTailAnomaly(BaseModel):type: Literal['feathers/wings/tail']anomaly_type: List[Literal['fluffed up','feather abnormalities','stained feathers','abnormal wing posture','missing limb',CommonAnomalies]]# --- Head-related Anomalies (including eyes) ---class HeadAnomaly(BaseModel):type: Literal['head incl. eyes']anomaly_type: List[Literal['ear changes','eye changes','tilted head',CommonAnomalies]]# Union of all possible anomaly types for specific body partsAnomalyType = Union[BeakAnomaly,BodyAnomaly,LegAnomaly,FeathersWingsTailAnomaly,HeadAnomaly]# Main PhysicalAnomaly class that logs anomalies across different body partsclass PhysicalAnomalies(BaseModel):physical_radio: str2 unmodified lines345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667682 unmodified lines# Define common anomalies as a Literal typeCommonAnomalies = Literal["blackened/burnt skin","blood","foreign body","fracture","injury","parasite","swelling","warty or tumor-like growth, crusts",]# --- Beak-related Anomalies ---class BeakAnomaly(BaseModel):type: Literal["beak"]anomaly_type: List[Literal["adhesion", "deformation", CommonAnomalies]]# --- Body-related Anomalies ---class BodyAnomaly(BaseModel):type: Literal["body"]anomaly_type: List[Literal["emaciation", "fluffed up", "stained feathers", CommonAnomalies]]# --- Legs-related Anomalies ---class LegAnomaly(BaseModel):type: Literal["legs"]anomaly_type: List[Literal["missing limb", "deformation", CommonAnomalies]]# --- Feathers/Wings/Tail-related Anomalies ---class FeathersWingsTailAnomaly(BaseModel):type: Literal["feathers/wings/tail"]anomaly_type: List[Literal["fluffed up","feather abnormalities","stained feathers","abnormal wing posture","missing limb",CommonAnomalies,]]# --- Head-related Anomalies (including eyes) ---class HeadAnomaly(BaseModel):type: Literal["head incl. eyes"]anomaly_type: List[Literal["ear changes", "eye changes", "tilted head", CommonAnomalies]]# Union of all possible anomaly types for specific body partsAnomalyType = Union[BeakAnomaly, BodyAnomaly, LegAnomaly, FeathersWingsTailAnomaly, HeadAnomaly]# Main PhysicalAnomaly class that logs anomalies across different body partsclass PhysicalAnomalies(BaseModel):physical_radio: str
1 unmodified line2345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758591 unmodified linefrom typing import Literal, List, Union, Optional# Define common anomalies as a Literal typeCommonAnomaliesSimple = Literal['injury','abnormal position']# --- Beak-related Anomalies ---class BeakAnomaly(BaseModel):type: Literal['beak']anomaly_type: List[Literal['adhesion/discharge',CommonAnomaliesSimple]]# --- Body-related Anomalies ---class BodyAnomaly(BaseModel):type: Literal['body']anomaly_type: List[Literal[CommonAnomaliesSimple]]# --- Feathers/Wings/Tail-related Anomalies ---class FeathersWingsTailAnomaly(BaseModel):type: Literal['feathers/wings/tail']anomaly_type: List[Literal['feather and skin change',CommonAnomaliesSimple]]# --- Head-related Anomalies (including eyes) ---class HeadAnomaly(BaseModel):type: Literal['head incl. eyes']anomaly_type: List[Literal['eye changes',CommonAnomaliesSimple]]# --- Legs-related Anomalies ---class LegAnomaly(BaseModel):type: Literal['legs']anomaly_type: List[Literal[CommonAnomaliesSimple]]# Union of all possible anomaly types for specific body partsAnomalyTypeSimple = Union[BeakAnomaly,BodyAnomaly,LegAnomaly,FeathersWingsTailAnomaly,HeadAnomaly]# Main PhysicalAnomaly class that logs anomalies across different body partsclass PhysicalAnomaliesSimple(BaseModel):physical_radio: str1 unmodified line23456789101112131415161718192021222324252627282930313233343536373839404142434445461 unmodified linefrom typing import Literal, List, Union, Optional# Define common anomalies as a Literal typeCommonAnomaliesSimple = Literal["injury", "abnormal position"]# --- Beak-related Anomalies ---class BeakAnomaly(BaseModel):type: Literal["beak"]anomaly_type: List[Literal["adhesion/discharge", CommonAnomaliesSimple]]# --- Body-related Anomalies ---class BodyAnomaly(BaseModel):type: Literal["body"]anomaly_type: List[Literal[CommonAnomaliesSimple]]# --- Feathers/Wings/Tail-related Anomalies ---class FeathersWingsTailAnomaly(BaseModel):type: Literal["feathers/wings/tail"]anomaly_type: List[Literal["feather and skin change", CommonAnomaliesSimple]]# --- Head-related Anomalies (including eyes) ---class HeadAnomaly(BaseModel):type: Literal["head incl. eyes"]anomaly_type: List[Literal["eye changes", CommonAnomaliesSimple]]# --- Legs-related Anomalies ---class LegAnomaly(BaseModel):type: Literal["legs"]anomaly_type: List[Literal[CommonAnomaliesSimple]]# Union of all possible anomaly types for specific body partsAnomalyTypeSimple = Union[BeakAnomaly, BodyAnomaly, LegAnomaly, FeathersWingsTailAnomaly, HeadAnomaly]# Main PhysicalAnomaly class that logs anomalies across different body partsclass PhysicalAnomaliesSimple(BaseModel):physical_radio: str
5 unmodified lines678910111213141516171819202122235 unmodified linesbox(250, 375, 350, 485),# 'Beak and mouth region',box(200, 450, 250, 485),# 'Feathers/Wings/Tail',box(50, 100, 725, 355),# 'Legs',box(325, 585, 450, 675),# 'Body'box(275, 510, 500, 565)]# Create a GeoDataFrame from these boxesgdf = gpd.GeoDataFrame({'geometry': bounding_boxes,'name': ['Head incl. eyes','Beak','Feathers/Wings/Tail','Legs','Body']})5 unmodified lines678910111213141516171819202122235 unmodified linesbox(250, 375, 350, 485),# 'Beak and mouth region',box(200, 450, 250, 485),# 'Feathers/Wings/Tail',box(50, 100, 725, 355),# 'Legs',box(325, 585, 450, 675),# 'Body'box(275, 510, 500, 565),]# Create a GeoDataFrame from these boxesgdf = gpd.GeoDataFrame({"geometry": bounding_boxes,"name": ["Head incl. eyes", "Beak", "Feathers/Wings/Tail", "Legs", "Body"],})
3 unmodified lines4567891011121314151617181920212223242526272829303 unmodified linesfrom dotenv import load_dotenvimport osload_dotenv()PATH_ASSETS = os.getenv('PATH_ASSETS')# Function to draw the bounding boxes on the imagedef draw_bounding_boxes(image_path, gdf):image = Image.open(image_path+'bird.png').convert("RGB")# Convert the image to an editable formatdraw = ImageDraw.Draw(image)# Optional: Load a font (requires a TTF file)# try:font = ImageFont.truetype(PATH_ASSETS + "fonts/LiberationSans-Regular.ttf",20)# Draw each bounding box on the imagefor _, row in gdf.iterrows():xmin, ymin, xmax, ymax = row['geometry'].boundsdraw.rectangle([xmin, ymin, xmax, ymax], outline="purple", width=2)draw.text((xmin, ymin-22), row['name'], fill="black", font=font)image.save(image_path+'bird_boxed.png', "PNG")if __name__ == "__main__":draw_bounding_boxes(PATH_ASSETS + 'images/', gdf)3 unmodified lines45678910111213141516171819202122232425262728293031323 unmodified linesfrom dotenv import load_dotenvimport osload_dotenv()PATH_ASSETS = os.getenv("PATH_ASSETS")# Function to draw the bounding boxes on the imagedef draw_bounding_boxes(image_path, gdf):image = Image.open(image_path + "bird.png").convert("RGB")# Convert the image to an editable formatdraw = ImageDraw.Draw(image)# Optional: Load a font (requires a TTF file)# try:font = ImageFont.truetype(PATH_ASSETS + "fonts/LiberationSans-Regular.ttf", 20)# Draw each bounding box on the imagefor _, row in gdf.iterrows():xmin, ymin, xmax, ymax = row["geometry"].boundsdraw.rectangle([xmin, ymin, xmax, ymax], outline="purple", width=2)draw.text((xmin, ymin - 22), row["name"], fill="black", font=font)image.save(image_path + "bird_boxed.png", "PNG")if __name__ == "__main__":draw_bounding_boxes(PATH_ASSETS + "images/", gdf)
129 unmodified lines130131132133129 unmodified lines"physical_anomaly_" + body_part.lower(), body_part_checkbox, individual)return individual129 unmodified lines130131132129 unmodified lines"physical_anomaly_" + body_part.lower(), body_part_checkbox, individual)return individual
10 unmodified lines111213141516171 unmodified line19202122232425262728293031323334353637383940414243444546474849505110 unmodified linesfrom validation_submission.utils_individual import add_data_to_individualload_dotenv()PATH_ASSETS = os.getenv('PATH_ASSETS')# Function to find the matching bounding box for a given point and return the image with boxesdef find_bounding_box(evt: gr.SelectData, img, section: str, mode: str):1 unmodified linepoint = Point(x, y)match = gdf[gdf.contains(point)]if not match.empty:matched_box = match.iloc[0]['name']checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs = process_body_parts(section, mode, matched_box)else:matched_box = Nonecheckbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs = process_body_parts(section, mode, matched_box)return checkbox_beak, text_beak, checkbox_body, text_body, checkbox_feathers, text_feathers, checkbox_head, text_head, checkbox_legs, text_legs# Gradio appdef create_bird_anatomy(visible, section: str):# Draw bounding boxes on the imageimg_with_boxes = gr.Image(value=PATH_ASSETS+'images/bird_boxed.png',show_label=False,height="600px",elem_id=section,visible=visible)return img_with_boxesdef show_physical(choice, section: str, individual):visible = set_visible(choice)physical_boxes = create_bird_anatomy(visible, section)individual = add_data_to_individual("physical_radio", choice, individual)return physical_boxes, individual10 unmodified lines11121314151617181 unmodified line202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808110 unmodified linesfrom validation_submission.utils_individual import add_data_to_individualload_dotenv()PATH_ASSETS = os.getenv("PATH_ASSETS")# Function to find the matching bounding box for a given point and return the image with boxesdef find_bounding_box(evt: gr.SelectData, img, section: str, mode: str):1 unmodified linepoint = Point(x, y)match = gdf[gdf.contains(point)]if not match.empty:matched_box = match.iloc[0]["name"](checkbox_beak,text_beak,checkbox_body,text_body,checkbox_feathers,text_feathers,checkbox_head,text_head,checkbox_legs,text_legs,) = process_body_parts(section, mode, matched_box)else:matched_box = None(checkbox_beak,text_beak,checkbox_body,text_body,checkbox_feathers,text_feathers,checkbox_head,text_head,checkbox_legs,text_legs,) = process_body_parts(section, mode, matched_box)return (checkbox_beak,text_beak,checkbox_body,text_body,checkbox_feathers,text_feathers,checkbox_head,text_head,checkbox_legs,text_legs,)# Gradio appdef create_bird_anatomy(visible, section: str):# Draw bounding boxes on the imageimg_with_boxes = gr.Image(value=PATH_ASSETS + "images/bird_boxed.png",show_label=False,height="600px",elem_id=section,visible=visible,)return img_with_boxesdef show_physical(choice, section: str, individual):visible = set_visible(choice)physical_boxes = create_bird_anatomy(visible, section)individual = add_data_to_individual("physical_radio", choice, individual)return physical_boxes, individual
1234569 unmodified lines1617181920212211 unmodified lines34353637import gradio as grgr.HTML('''<style># .custom-button {# background-color: #3B4C54;9 unmodified lines# border-radius: 8px;# }</style>''')# gr.HTML('''# <style>11 unmodified lines# border-radius: 8px;# }# </style># ''')12345679 unmodified lines171819202122232411 unmodified lines36373839import gradio as grgr.HTML("""<style># .custom-button {# background-color: #3B4C54;9 unmodified lines# border-radius: 8px;# }</style>""")# gr.HTML('''# <style>11 unmodified lines# border-radius: 8px;# }# </style># ''')
123412 unmodified lines171819202122232425269 unmodified lines363738394041424344454627 unmodified lines7475767778798081828384css_for_error_box= """#error {background-color: #e82323 !important;color: white !important;font-weight: bold;}12 unmodified lines}/* Secondary color for headers and panels */.gradio-container .card,.gradio-container h1,.gradio-container h2,.gradio-container h3,.gradio-container h4 {background-color: #3F543B;color: #ffffff; /* Ensuring text is readable */9 unmodified lines}/* Olive green color for headers within the wounded section */#wounded h1,#wounded h2,#wounded h3,#wounded h4,#wounded h5,#wounded h6 {color: #ffffff; /* Olive green color for header text */background-color: #503B54; /* No background color for headers */27 unmodified lines}/* Brown color for headers within the dead section */#dead h1,#dead h2,#dead h3,#dead h4,#dead h5,#dead h6 {color: #ffffff; /* Olive green color for header text */background-color: #54433B; /* No background color for headers */123412 unmodified lines171819202122232425269 unmodified lines363738394041424344454627 unmodified lines7475767778798081828384css_for_error_box = """#error {background-color: #e82323 !important;color: white !important;font-weight: bold;}12 unmodified lines}/* Secondary color for headers and panels */.gradio-container .card,.gradio-container h1,.gradio-container h2,.gradio-container h3,.gradio-container h4 {background-color: #3F543B;color: #ffffff; /* Ensuring text is readable */9 unmodified lines}/* Olive green color for headers within the wounded section */#wounded h1,#wounded h2,#wounded h3,#wounded h4,#wounded h5,#wounded h6 {color: #ffffff; /* Olive green color for header text */background-color: #503B54; /* No background color for headers */27 unmodified lines}/* Brown color for headers within the dead section */#dead h1,#dead h2,#dead h3,#dead h4,#dead h5,#dead h6 {color: #ffffff; /* Olive green color for header text */background-color: #54433B; /* No background color for headers */
12345675 unmodified lines1314151617181920212223242526272829303132333435from datasets import load_dataset, DownloadModeimport jsonimport osfrom huggingface_hub import HfApi , hf_hub_downloaddataset_id = "SDSC/digiwild-dataset"token = os.getenv("HUGGINGFACE_TOKEN")5 unmodified linesfiles = api.list_repo_files(dataset_id, repo_type="dataset")json_files = [file for file in files if file.endswith(".json")]# Load the metadata compilationtry:data_files = "data/train-00000-of-00001.parquet"metadata = load_dataset(dataset_id,data_files=data_files)# Add new json entries to datasetfor file in json_files:file = hf_hub_download(repo_id=dataset_id, filename=file, repo_type="dataset")with open(file, "r") as f:new = json.load(f)if not(new["image_md5"] in metadata["train"]["image_md5"]):metadata["train"] = metadata["train"].add_item(new)except:metadata = load_dataset(dataset_id,data_files=json_files)metadata.push_to_hub(dataset_id, token=token)12345675 unmodified lines13141516171819202122232425262728293031from datasets import load_dataset, DownloadModeimport jsonimport osfrom huggingface_hub import HfApi, hf_hub_downloaddataset_id = "SDSC/digiwild-dataset"token = os.getenv("HUGGINGFACE_TOKEN")5 unmodified linesfiles = api.list_repo_files(dataset_id, repo_type="dataset")json_files = [file for file in files if file.endswith(".json")]# Load the metadata compilationtry:data_files = "data/train-00000-of-00001.parquet"metadata = load_dataset(dataset_id, data_files=data_files)# Add new json entries to datasetfor file in json_files:file = hf_hub_download(repo_id=dataset_id, filename=file, repo_type="dataset")with open(file, "r") as f:new = json.load(f)if not (new["image_md5"] in metadata["train"]["image_md5"]):metadata["train"] = metadata["train"].add_item(new)except:metadata = load_dataset(dataset_id, data_files=json_files)metadata.push_to_hub(dataset_id, token=token)
123456789101112131415161718import gradio as gr#---------------------------------------------------------def create_checkbox(value, section, label_checkbox, visible, options, descriptions):descriptions_info = "<br><br>".join([f"* **{option}**: {description}" for option, description in zip(options, descriptions)])checkbox = gr.CheckboxGroup(options,label=label_checkbox + f" {value}:",visible=visible,interactive=True,elem_id=section)text = gr.Markdown(descriptions_info,label = "Info",visible=visible,#interactive=False,#lines=13,#max_lines=15,elem_id=section)return checkbox, text12345678910111213141516171819202122232425262728import gradio as gr# ---------------------------------------------------------def create_checkbox(value, section, label_checkbox, visible, options, descriptions):descriptions_info = "<br><br>".join([f"* **{option}**: {description}"for option, description in zip(options, descriptions)])checkbox = gr.CheckboxGroup(options,label=label_checkbox + f" {value}:",visible=visible,interactive=True,elem_id=section,)text = gr.Markdown(descriptions_info,label="Info",visible=visible,# interactive=False,# lines=13,# max_lines=15,elem_id=section,)return checkbox, text
1 unmodified line2345678910111213141516171819201 unmodified lineimport osfrom dotenv import load_dotenvimport osload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv('PATH_ASSETS')PATH_CONFIG = PATH + PATH_ASSETS + "config/"def load_config(file_path):with open(file_path) as f:config = json.load(f)return configdef get_custom_config_dropdowns(config_path):dropdown_config_path = PATH_CONFIG + config_pathdropdown_config = load_config(dropdown_config_path)return dropdown_config1 unmodified line234567891011121314151617181920211 unmodified lineimport osfrom dotenv import load_dotenvimport osload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv("PATH_ASSETS")PATH_CONFIG = PATH + PATH_ASSETS + "config/"def load_config(file_path):with open(file_path) as f:config = json.load(f)return configdef get_custom_config_dropdowns(config_path):dropdown_config_path = PATH_CONFIG + config_pathdropdown_config = load_config(dropdown_config_path)return dropdown_config
123456def set_visible(choice):if choice=="Yes":visible = Trueelse:visible=Falsereturn visible123456def set_visible(choice):if choice == "Yes":visible = Trueelse:visible = Falsereturn visible
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071#### PROCESS FUNCTIONSdef process_circumstance(data):fields_to_check = ["option_dropdown", "open_field", "extra"]reformatted ={}if ("circumstance_radio" in data.keys()) and ("circumstance" in data.keys()) and ("circumstance_type" in data.keys()) and (data["circumstance_radio"] == "Yes"):reformatted["circumstance_radio"] = data["circumstance_radio"]reformatted["circumstance"] = data["circumstance"]reformatted["circumstance_type"] = {}if "type" in data["circumstance_type"]:reformatted["circumstance_type"]["type"] = data["circumstance_type"]["type"]for field in fields_to_check:if not data["circumstance_type"][field+"_label"] == "NA":val = data[f"circumstance_{field}"]key = data["circumstance_type"][field+"_label"]reformatted["circumstance_type"][key] = valelse:reformatted["circumstance_radio"] = Nonereformatted["circumstance"] = Nonereformatted["circumstance_type"] = {}return reformatteddef process_behaviors(data):behaviors =[]reformatted = {}if ("behaviors_radio" in data.keys()) and ("behaviors_type" in data.keys()) and (data["behaviors_radio"] == "Yes"):reformatted["behaviors_radio"] = data["behaviors_radio"]for type in data["behaviors_type"]:new_behavior = {}new_behavior["type"] = typebehaviors.append(new_behavior)reformatted["behaviors_type"] = behaviorselse:reformatted["behaviors_radio"] = Nonereformatted["behaviors_type"] = []return reformatteddef process_physical(data):body_parts= ["beak", "body", "legs", "feathers/wings/tail", "head incl. eyes"]body_parts_search = ["beak", "body", "legs", "feathers", "head"]anomalies=[]reformatted = {}if ("physical_radio" in data.keys()) and (data["physical_radio"] == "Yes") and any("type_" in key for key in data.keys()) and any("anomaly_" in key for key in data.keys()):reformatted["physical_radio"] = data["physical_radio"]for b, body_part in enumerate(body_parts_search):anomaly = {}for key, val in data.items():if "type_"+ body_part in key:anomaly["type"] = body_parts[b]elif "anomaly_"+ body_part in key:anomaly["anomaly_type"] = valif anomaly:anomalies.append(anomaly)reformatted["physical_anomalies_type"] = anomalieselse:reformatted["physical_radio"] = Nonereformatted["physical_anomalies_type"] = []return reformatteddef process_followup(data):followup_events = []for key, val in data.items():followup_event={}type = key.split("followup")[-1]option = type.split(" ")[-1]followup_event["type"] = type.strip()followup_event[option.strip()] = valfollowup_events.append(followup_event)reformatted ={}reformatted["follow_up_events"] = followup_eventsreturn reformatted1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889#### PROCESS FUNCTIONSdef process_circumstance(data):fields_to_check = ["option_dropdown", "open_field", "extra"]reformatted = {}if (("circumstance_radio" in data.keys())and ("circumstance" in data.keys())and ("circumstance_type" in data.keys())and (data["circumstance_radio"] == "Yes")):reformatted["circumstance_radio"] = data["circumstance_radio"]reformatted["circumstance"] = data["circumstance"]reformatted["circumstance_type"] = {}if "type" in data["circumstance_type"]:reformatted["circumstance_type"]["type"] = data["circumstance_type"]["type"]for field in fields_to_check:if not data["circumstance_type"][field + "_label"] == "NA":val = data[f"circumstance_{field}"]key = data["circumstance_type"][field + "_label"]reformatted["circumstance_type"][key] = valelse:reformatted["circumstance_radio"] = Nonereformatted["circumstance"] = Nonereformatted["circumstance_type"] = {}return reformatteddef process_behaviors(data):behaviors = []reformatted = {}if (("behaviors_radio" in data.keys())and ("behaviors_type" in data.keys())and (data["behaviors_radio"] == "Yes")):reformatted["behaviors_radio"] = data["behaviors_radio"]for type in data["behaviors_type"]:new_behavior = {}new_behavior["type"] = typebehaviors.append(new_behavior)reformatted["behaviors_type"] = behaviorselse:reformatted["behaviors_radio"] = Nonereformatted["behaviors_type"] = []return reformatteddef process_physical(data):body_parts = ["beak", "body", "legs", "feathers/wings/tail", "head incl. eyes"]body_parts_search = ["beak", "body", "legs", "feathers", "head"]anomalies = []reformatted = {}if (("physical_radio" in data.keys())and (data["physical_radio"] == "Yes")and any("type_" in key for key in data.keys())and any("anomaly_" in key for key in data.keys())):reformatted["physical_radio"] = data["physical_radio"]for b, body_part in enumerate(body_parts_search):anomaly = {}for key, val in data.items():if "type_" + body_part in key:anomaly["type"] = body_parts[b]elif "anomaly_" + body_part in key:anomaly["anomaly_type"] = valif anomaly:anomalies.append(anomaly)reformatted["physical_anomalies_type"] = anomalieselse:reformatted["physical_radio"] = Nonereformatted["physical_anomalies_type"] = []return reformatteddef process_followup(data):followup_events = []for key, val in data.items():followup_event = {}type = key.split("followup")[-1]option = type.split(" ")[-1]followup_event["type"] = type.strip()followup_event[option.strip()] = valfollowup_events.append(followup_event)reformatted = {}reformatted["follow_up_events"] = followup_eventsreturn reformatted
3 unmodified lines45678910111213141516171819203 unmodified linesfrom dotenv import load_dotenvimport osload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv('PATH_ASSETS')PATH_ICONS = PATH + PATH_ASSETS + "icons/"def reset_individual(individual):individual = {}return individualdef reset_error_box(error_icon, error_box):error_icon = gr.Image(PATH_ICONS+"supprimer.png", height=80, width=80, visible=False)error_box = gr.Text(value=None, visible=False)return error_icon, error_box3 unmodified lines456789101112131415161718192021222324253 unmodified linesfrom dotenv import load_dotenvimport osload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv("PATH_ASSETS")PATH_ICONS = PATH + PATH_ASSETS + "icons/"def reset_individual(individual):individual = {}return individualdef reset_error_box(error_icon, error_box):error_icon = gr.Image(PATH_ICONS + "supprimer.png", height=80, width=80, visible=False)error_box = gr.Text(value=None, visible=False)return error_icon, error_box
123456789101112import jsonfrom validation_submission.validation import validate_individualimport gradio as grfrom huggingface_hub import HfApiimport osdef validate_save_individual(data, error_icon, error_box, mode):individual, error_icon, error_box = validate_individual(data, error_icon, error_box, mode)if individual:print("pushing to hugging face")push_to_dataset_hf(individual.model_dump())1234567891011121314import jsonfrom validation_submission.validation import validate_individualimport gradio as grfrom huggingface_hub import HfApiimport osdef validate_save_individual(data, error_icon, error_box, mode):individual, error_icon, error_box = validate_individual(data, error_icon, error_box, mode)if individual:print("pushing to hugging face")push_to_dataset_hf(individual.model_dump())
1 unmodified line2345678910111213141516171 unmodified lineimport stringimport hashlibdef generate_random_md5():# Generate a random stringrandom_string = ''.join(random.choices(string.ascii_letters + string.digits, k=16))# Encode the string and compute its MD5 hashmd5_hash = hashlib.md5(random_string.encode()).hexdigest()return md5_hashdef add_data_to_individual(key, value, individual):individual[key] = valuereturn individual1 unmodified line23456789101112131415161 unmodified lineimport stringimport hashlibdef generate_random_md5():# Generate a random stringrandom_string = "".join(random.choices(string.ascii_letters + string.digits, k=16))# Encode the string and compute its MD5 hashmd5_hash = hashlib.md5(random_string.encode()).hexdigest()return md5_hashdef add_data_to_individual(key, value, individual):individual[key] = valuereturn individual
123456789from validation_submission.utils_individual import add_data_to_individualdef save_details(tag, data, individual):individual = add_data_to_individual(tag, data, individual)return individualdef save_image(camera, individual):individual = add_data_to_individual("image", camera.tolist(), individual)return individual1234567891011from validation_submission.utils_individual import add_data_to_individualdef save_details(tag, data, individual):individual = add_data_to_individual(tag, data, individual)return individualdef save_image(camera, individual):individual = add_data_to_individual("image", camera.tolist(), individual)return individual
19 unmodified lines2021222324252627284 unmodified lines333435363738394041424344454610 unmodified lines5758596061626363 unmodified lines1271281291301311321331341351361374 unmodified lines14214314414514614714814915015115219 unmodified linesfrom dotenv import load_dotenvimport osload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv('PATH_ASSETS')PATH_ICONS = PATH + PATH_ASSETS + "icons/"4 unmodified linesextract[key] = valreturn extractdef field_checker(data):img = ImageBase64.to_base64(data["image"]) if "image" in data.keys() else Nonegeolocalisation = data["geolocalisation"] if "geolocalisation" in data.keys() else Nonespecie = data["specie"] if "specie" in data.keys() else "NA"number = data["number"] if "specie" in data.keys() else 1comments = data["comments"] if "specie" in data.keys() else "NA"return img, geolocalisation, specie, number, commentsdef validate_individual(data, error_icon, error_box, mode: str):error_icon, error_box = reset_error_box(error_icon, error_box)# data = get_json_one_individual() # TODO: This should change10 unmodified linesdata["wounded_state"] = "No"data["dead_state"] = "No"if (data["wounded_state"] == "Yes") or (data["dead_state"] == "Yes"):data_wounded_dead = datacircumstance, error_circumstance = validate_circumstance(data_wounded_dead)physical, error_physical = validate_physical(data_wounded_dead, mode)followup, error_followup = validate_follow_up(data_wounded_dead)63 unmodified linesor error_physicalor error_individual):error_icon = gr.Image(PATH_ICONS+"supprimer.png", height=80, width=80,interactive=False,show_fullscreen_button = False, show_share_button=False,show_download_button=False, show_label=False,visible=True)error_box = show_error(error_box,error_behavior,4 unmodified lines)individual = Noneelse:error_icon = gr.Image(PATH_ICONS+"correct.png", height=80, width=80,interactive=False,show_fullscreen_button = False, show_share_button=False,show_download_button=False, show_label=False,visible=True)error_box = gr.Text(label="ALL VALID.",value="Record Registered. Remember to press the CLEAR button before submitting a new record.",19 unmodified lines202122232425262728294 unmodified lines34353637383940414243444546474849505110 unmodified lines6263646566676863 unmodified lines1321331341351361371381391401411421431441451461471484 unmodified lines15315415515615715815916016116216316416516616716816919 unmodified linesfrom dotenv import load_dotenvimport osload_dotenv()PATH = os.getcwd() + "/"PATH_ASSETS = os.getenv("PATH_ASSETS")PATH_ICONS = PATH + PATH_ASSETS + "icons/"4 unmodified linesextract[key] = valreturn extractdef field_checker(data):img = ImageBase64.to_base64(data["image"]) if "image" in data.keys() else Nonegeolocalisation = (data["geolocalisation"] if "geolocalisation" in data.keys() else None)specie = data["specie"] if "specie" in data.keys() else "NA"number = data["number"] if "specie" in data.keys() else 1comments = data["comments"] if "specie" in data.keys() else "NA"return img, geolocalisation, specie, number, commentsdef validate_individual(data, error_icon, error_box, mode: str):error_icon, error_box = reset_error_box(error_icon, error_box)# data = get_json_one_individual() # TODO: This should change10 unmodified linesdata["wounded_state"] = "No"data["dead_state"] = "No"if (data["wounded_state"] == "Yes") or (data["dead_state"] == "Yes"):data_wounded_dead = datacircumstance, error_circumstance = validate_circumstance(data_wounded_dead)physical, error_physical = validate_physical(data_wounded_dead, mode)followup, error_followup = validate_follow_up(data_wounded_dead)63 unmodified linesor error_physicalor error_individual):error_icon = gr.Image(PATH_ICONS + "supprimer.png",height=80,width=80,interactive=False,show_fullscreen_button=False,show_share_button=False,show_download_button=False,show_label=False,visible=True,)error_box = show_error(error_box,error_behavior,4 unmodified lines)individual = Noneelse:error_icon = gr.Image(PATH_ICONS + "correct.png",height=80,width=80,interactive=False,show_fullscreen_button=False,show_share_button=False,show_download_button=False,show_label=False,visible=True,)error_box = gr.Text(label="ALL VALID.",value="Record Registered. Remember to press the CLEAR button before submitting a new record.",
4 unmodified lines56784 unmodified linespillowpython-dotenvdatasetshuggingface_hub4 unmodified lines56784 unmodified linespillowpython-dotenvdatasetshuggingface_hub
.github/workflows/sync_dataset_hf.yml+2-2
.gitignore+2-2
.pre-commit-config.yaml+1-1
Dockerfile+2-2
README.md+19-21
app/.env.dist+2-1
app/about.py+29-20
app/assets/config/config_checkbox_behavior.json+2-2
app/assets/config/config_checkbox_behavior_simple.json+2-2
app/assets/config/config_checkbox_physical.json+2-2
app/assets/config/config_checkbox_physical_simple.json+2-2
app/assets/config/config_dropdown_circumstances.json+27-27
app/assets/config/config_followup.json+2-2
app/behavior/class_behavior.py+36-15
app/circumstances/circumstances.py+99-42
app/circumstances/class_circumstance.py+186-73
app/contacts.py+56-41
app/dead_wounded/dead.py+86-27
app/dead_wounded/wounded.py+104-36
app/follow_up/class_follow_up.py+28-20
app/follow_up/followup_events.py+63-24
app/geolocalisation/class_geolocalisation.py+5-3
app/geolocalisation/js_geolocation.py+9-7
app/geolocalisation/maps.py+27-19
app/main.py+8-5
app/mode_advanced.py+854-300
app/mode_simple.py+829-286
app/physical/class_physical.py+38-48
app/physical/class_physical_simple.py+19-32
app/physical/physical_boxes_define.py+10-10
app/physical/physical_boxes_map.py+10-8
app/physical/physical_checkbox.py-1
app/physical/physical_select_animal.py+48-18
app/styling/style.py+6-4
app/styling/theme.py+15-15
app/sync_dataset_hf.py+11-15
app/utils/utils_checkbox.py+25-15
app/utils/utils_config.py+4-3
app/utils/utils_visible.py+3-3
app/validation_submission/processing.py+43-25
app/validation_submission/resets.py+7-2
app/validation_submission/submission.py+4-2
app/validation_submission/utils_individual.py+4-5
app/validation_submission/utils_save.py+6-4
app/validation_submission/validation.py+31-14
requirements.txt+1-1