rosemariafontana commited on
Commit
de527c9
·
verified ·
1 Parent(s): c85ff27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -5,7 +5,6 @@ from urllib.parse import urljoin, urlencode, quote
5
  from gradio_toggle import Toggle
6
  import json
7
  import yaml
8
- import STPyV8
9
 
10
  from process_data import parse_survey_stack_parameters, parse_survey_stack_data, process_specifications
11
 
@@ -60,10 +59,11 @@ def process_survey(button_type, survey_submission_ID):
60
  except Exception as e:
61
  return f"An error occurred while fetching the survey data: {e}"
62
 
63
- class Global(STPyV8.JSClass):
64
- def __init__(self):
65
- self.mySubmissionData = None
66
-
 
67
  def display_parameter_survey():
68
  base_url = "https://app.surveystack.io/groups/"
69
  group_id = "5e95e368fbbf75000146a006" # Group ID "Our-Sci"
@@ -84,16 +84,19 @@ def display_parameter_survey():
84
  if (event.origin === "https://app.surveystack.io" && event.data.type === "SUBMISSION_SUBMIT_SUCCESS") {{
85
  const data = event.data.payload.submissionId;
86
  console.log("Submission Data:", data);
87
- window.huggingface.variables.mySubmissionData = data;
88
- }}
 
 
 
 
 
 
 
89
  }});
90
  </script>
91
  """
92
 
93
- with STPyV8.JSContext(Global()) as ctxt:
94
- submission_data = ctxt.eval("window.huggingface.variables.mySubmissionData")
95
- print("Submission Data:", submission_data)
96
-
97
  return iframe_html
98
 
99
  def display_data_survey():
@@ -131,6 +134,7 @@ def update_toggle(toggle, farm_output_box, interactions_output_box, trials_outpu
131
  return original_outputs[0], original_outputs[1], original_outputs[2]
132
 
133
  with gr.Blocks() as app:
 
134
  with gr.Row():
135
  data_survey_output = gr.HTML(value=display_data_survey())
136
 
 
5
  from gradio_toggle import Toggle
6
  import json
7
  import yaml
 
8
 
9
  from process_data import parse_survey_stack_parameters, parse_survey_stack_data, process_specifications
10
 
 
59
  except Exception as e:
60
  return f"An error occurred while fetching the survey data: {e}"
61
 
62
+ def submit_data(data):
63
+ # This function will handle the submission data sent from JavaScript
64
+ print("Received submission data:", data)
65
+ return "Data processed successfully!"
66
+
67
  def display_parameter_survey():
68
  base_url = "https://app.surveystack.io/groups/"
69
  group_id = "5e95e368fbbf75000146a006" # Group ID "Our-Sci"
 
84
  if (event.origin === "https://app.surveystack.io" && event.data.type === "SUBMISSION_SUBMIT_SUCCESS") {{
85
  const data = event.data.payload.submissionId;
86
  console.log("Submission Data:", data);
87
+
88
+ fetch('/submit', {{
89
+ method: 'POST',
90
+ headers: {{
91
+ 'Content-Type': 'application/json',
92
+ }},
93
+ body: JSON.stringify({{ submissionId: data }}),
94
+ }});
95
+ }}
96
  }});
97
  </script>
98
  """
99
 
 
 
 
 
100
  return iframe_html
101
 
102
  def display_data_survey():
 
134
  return original_outputs[0], original_outputs[1], original_outputs[2]
135
 
136
  with gr.Blocks() as app:
137
+ app.add_api_route('/submit', submit_data, methods=['POST'])
138
  with gr.Row():
139
  data_survey_output = gr.HTML(value=display_data_survey())
140