vancauwe commited on
Commit
ee406aa
·
1 Parent(s): f19bc2d

feat: save df as json of all records

Browse files
app/assets/config/config_df.json CHANGED
@@ -10,6 +10,7 @@
10
  "circumstance_dropdown_level2",
11
  "circumstance_openfield_level2",
12
  "circumstance_dropdown_extra_level2",
 
13
  "physical_changes_beak",
14
  "physical_changes_body",
15
  "physical_changes_head",
 
10
  "circumstance_dropdown_level2",
11
  "circumstance_openfield_level2",
12
  "circumstance_dropdown_extra_level2",
13
+ "behavior",
14
  "physical_changes_beak",
15
  "physical_changes_body",
16
  "physical_changes_head",
app/main_multianimal.py CHANGED
@@ -3,7 +3,7 @@ from gradio_modal import Modal
3
 
4
  from utils_df import get_headers
5
  from utils_json import *
6
- from utils_df import save_individual_to_df, get_headers
7
  from maps import get_location
8
  from functools import partial
9
  from dead import show_section_dead
@@ -17,8 +17,9 @@ from style import *
17
  from theme import theme, css
18
 
19
  with gr.Blocks(theme=theme, css=css) as demo:
20
- # with gr.Tab("Tab 1"):
21
- show_modal = gr.Button("Add an Animal")
 
22
  df = gr.Dataframe(headers=get_headers(),
23
  visible=False)
24
  with Modal(visible=False) as modal:
@@ -181,6 +182,7 @@ with gr.Blocks(theme=theme, css=css) as demo:
181
 
182
  # ---------------------------------------------------------
183
  # Add One Individual's Data to the Dataframe
 
184
  with gr.Row():
185
  button_df = gr.Button("Submit Animal Report", scale = 3)
186
  button_clear = gr.ClearButton(scale = 1,
@@ -200,8 +202,12 @@ with gr.Blocks(theme=theme, css=css) as demo:
200
  inputs=[df],
201
  outputs=[df])
202
  button_df.click(lambda: Modal(visible=False), None, modal)
 
 
 
203
  show_modal.click(lambda: Modal(visible=True), None, modal)
204
  show_modal.click(create_json)
 
205
 
206
 
207
 
 
3
 
4
  from utils_df import get_headers
5
  from utils_json import *
6
+ from utils_df import save_individual_to_df, get_headers, save_and_rest_df
7
  from maps import get_location
8
  from functools import partial
9
  from dead import show_section_dead
 
17
  from theme import theme, css
18
 
19
  with gr.Blocks(theme=theme, css=css) as demo:
20
+ with gr.Row():
21
+ show_modal = gr.Button("Add an Animal", scale=3)
22
+ submit_button = gr.Button("Submit All Animals", scale=1)
23
  df = gr.Dataframe(headers=get_headers(),
24
  visible=False)
25
  with Modal(visible=False) as modal:
 
182
 
183
  # ---------------------------------------------------------
184
  # Add One Individual's Data to the Dataframe
185
+ # And Allow clearing of all previous output
186
  with gr.Row():
187
  button_df = gr.Button("Submit Animal Report", scale = 3)
188
  button_clear = gr.ClearButton(scale = 1,
 
202
  inputs=[df],
203
  outputs=[df])
204
  button_df.click(lambda: Modal(visible=False), None, modal)
205
+
206
+ # ---------------------------------------------------------
207
+ # Event Functions of the landing page buttons
208
  show_modal.click(lambda: Modal(visible=True), None, modal)
209
  show_modal.click(create_json)
210
+ submit_button.click(save_and_rest_df, inputs=[df], outputs=[df])
211
 
212
 
213
 
app/utils_df.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  import pandas as pd
3
  from dotenv import load_dotenv
4
  from utils_config import load_config
5
- from utils_json import get_json_one_individual
6
  import os
7
  load_dotenv()
8
  PATH = os.getcwd() + "/"
@@ -36,3 +36,9 @@ def save_individual_to_df(df):
36
  value=df_new,
37
  headers=headers)
38
  return df_gr
 
 
 
 
 
 
 
2
  import pandas as pd
3
  from dotenv import load_dotenv
4
  from utils_config import load_config
5
+ from utils_json import get_json_one_individual, save_all_animals
6
  import os
7
  load_dotenv()
8
  PATH = os.getcwd() + "/"
 
36
  value=df_new,
37
  headers=headers)
38
  return df_gr
39
+
40
+ def save_and_rest_df(df):
41
+ save_all_animals(df)
42
+ df = gr.Dataframe(headers=get_headers(),
43
+ visible=False)
44
+ return df
app/utils_json.py CHANGED
@@ -1,15 +1,14 @@
1
  import json
 
2
 
3
  def create_json(one_individual={}):
4
  # Serializing json
5
  one_individual = json.dumps(one_individual)
6
- # Writing to sample.json
7
  with open("data/one_individual.json", "w") as outfile:
8
  outfile.write(one_individual)
9
 
10
  def add_data_to_individual(key, value):
11
  with open("data/one_individual.json", 'r') as openfile:
12
- # Reading from json file
13
  one_individual = json.load(openfile)
14
  one_individual[key] = value
15
  create_json(one_individual)
@@ -19,3 +18,9 @@ def get_json_one_individual():
19
  one_individual = json.load(openfile)
20
  return one_individual
21
 
 
 
 
 
 
 
 
1
  import json
2
+ import gradio as gr
3
 
4
  def create_json(one_individual={}):
5
  # Serializing json
6
  one_individual = json.dumps(one_individual)
 
7
  with open("data/one_individual.json", "w") as outfile:
8
  outfile.write(one_individual)
9
 
10
  def add_data_to_individual(key, value):
11
  with open("data/one_individual.json", 'r') as openfile:
 
12
  one_individual = json.load(openfile)
13
  one_individual[key] = value
14
  create_json(one_individual)
 
18
  one_individual = json.load(openfile)
19
  return one_individual
20
 
21
+
22
+ def save_all_animals(df):
23
+ all_animals = df.to_json(orient="records")
24
+ with open("data/all_animals.json", "w") as outfile:
25
+ outfile.write(all_animals)
26
+