rosemariafontana commited on
Commit
6ee4ee9
·
verified ·
1 Parent(s): 4adf938

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -1
app.py CHANGED
@@ -12,6 +12,19 @@ global parsed_input_data
12
  global original_outputs, yaml_outputs
13
 
14
  def process_survey(button_type, survey_submission_ID):
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  if button_type == 'data':
16
  survey_id = "671fc52152e3225d7de349e6"
17
 
@@ -58,6 +71,15 @@ def process_survey(button_type, survey_submission_ID):
58
 
59
 
60
  def display_parameter_survey():
 
 
 
 
 
 
 
 
 
61
  base_url = "https://app.surveystack.io/groups/"
62
  group_id = "5e95e368fbbf75000146a006" # Group ID "Our-Sci"
63
  survey_id = "671fe2d352e3225d7de34afc" # survey id for parameter survey
@@ -74,6 +96,15 @@ def display_parameter_survey():
74
  return iframe_html
75
 
76
  def display_data_survey():
 
 
 
 
 
 
 
 
 
77
  base_url = "https://app.surveystack.io/groups/"
78
  group_id = "5e95e368fbbf75000146a006" # Group ID "Our-Sci"
79
  survey_id = "671fc52152e3225d7de349e6" # survey id for data survey
@@ -88,6 +119,21 @@ def display_data_survey():
88
  return iframe_html
89
 
90
  def update_toggle(toggle, farm_output_box, interactions_output_box, trials_output_box):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  global original_outputs, yaml_outputs
92
 
93
  if toggle and not yaml_outputs:
@@ -108,6 +154,7 @@ def update_toggle(toggle, farm_output_box, interactions_output_box, trials_outpu
108
  return original_outputs[0], original_outputs[1], original_outputs[2]
109
 
110
  with gr.Blocks() as app:
 
111
  with gr.Row():
112
  data_survey_output = gr.HTML(value=display_data_survey())
113
 
@@ -145,5 +192,5 @@ with gr.Blocks() as app:
145
  outputs=[get_survey_back, parameter_survey_output, data_survey_output, data_submit_button, survey2_submission_ID, param_submit_button]
146
  )
147
 
148
- # Comment to rerun
149
  app.launch()
 
12
  global original_outputs, yaml_outputs
13
 
14
  def process_survey(button_type, survey_submission_ID):
15
+ """
16
+ Gets the data from the survey submission, then processes it with models to get output (data-filled) JSON Schemas.
17
+ parse_survey_stack_data and parse_survey_stack_parameters complete the "back-end" data processing and can be found in a separate file
18
+
19
+ Args:
20
+ button_type: (str) 'data' or (str) 'param' indicating whether processing the data survey or the parameter survey. When the parameter survey is processed, it sends the data for further processing.
21
+ survey_submission_ID: (str) Survey Submission ID (for retrieving survey)
22
+
23
+ Returns:
24
+ (1) All front-end interactivity for hiding already used elements and showing new ones
25
+ (2) when button-type == 'data', the parsed input data
26
+ (3) when button-type == 'param', 3 JSONs representing the schemas for farm activity, interactions, and scientific trials
27
+ """
28
  if button_type == 'data':
29
  survey_id = "671fc52152e3225d7de349e6"
30
 
 
71
 
72
 
73
  def display_parameter_survey():
74
+ """
75
+ Display parameter survey based on the IDs necessary to render the survey
76
+
77
+ Args:
78
+ None
79
+
80
+ Returns:
81
+ HTML of survey in an iframe which gradio renders automagically in the variable parameter_survey_output
82
+ """
83
  base_url = "https://app.surveystack.io/groups/"
84
  group_id = "5e95e368fbbf75000146a006" # Group ID "Our-Sci"
85
  survey_id = "671fe2d352e3225d7de34afc" # survey id for parameter survey
 
96
  return iframe_html
97
 
98
  def display_data_survey():
99
+ """
100
+ Display data survey based on the IDs necessary to render the survey
101
+
102
+ Args:
103
+ None
104
+
105
+ Returns:
106
+ HTML of survey in an iframe which gradio renders automagically in the variable data_survey_output
107
+ """
108
  base_url = "https://app.surveystack.io/groups/"
109
  group_id = "5e95e368fbbf75000146a006" # Group ID "Our-Sci"
110
  survey_id = "671fc52152e3225d7de349e6" # survey id for data survey
 
119
  return iframe_html
120
 
121
  def update_toggle(toggle, farm_output_box, interactions_output_box, trials_output_box):
122
+ """
123
+ Used as function for toggle (button that you can slide left and right).
124
+ Allows for data to be transformed between JSON and YAML forms, without losing either
125
+ Both are persisted as globals (not a great practice in general) but allows for swapping between for viewing
126
+ Toggle is not a part of base gradio and it was added additionally from here https://github.com/dwancin/gradio-toggle
127
+
128
+ Args:
129
+ toggle: the Toggle element
130
+ farm_output_box: the text box designated for displaying the farm activity data JSON
131
+ interactions_output_box: the text box designated for displaying the interactions data JSON
132
+ trials_output_box: the text box designated for displaying the trials data JSON
133
+
134
+ Returns:
135
+ 3 YAML/JSON outputs displayed in the appropriate textboxes
136
+ """
137
  global original_outputs, yaml_outputs
138
 
139
  if toggle and not yaml_outputs:
 
154
  return original_outputs[0], original_outputs[1], original_outputs[2]
155
 
156
  with gr.Blocks() as app:
157
+ # This is the main driver of the program that sets up the gradio front end pieces, as well as specific interactivity with buttons
158
  with gr.Row():
159
  data_survey_output = gr.HTML(value=display_data_survey())
160
 
 
192
  outputs=[get_survey_back, parameter_survey_output, data_survey_output, data_submit_button, survey2_submission_ID, param_submit_button]
193
  )
194
 
195
+ # This starts the program
196
  app.launch()