Update app.py
Browse files
app.py
CHANGED
|
@@ -5,16 +5,21 @@ from urllib.parse import urljoin, urlencode, quote
|
|
| 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 |
|
| 11 |
global parsed_input_data
|
| 12 |
global original_outputs, yaml_outputs
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
print("
|
|
|
|
| 17 |
|
|
|
|
| 18 |
if button_type == 'data':
|
| 19 |
survey_id = "671fc52152e3225d7de349e6"
|
| 20 |
|
|
@@ -59,10 +64,6 @@ def process_survey(button_type, survey_submission_ID):
|
|
| 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/"
|
|
@@ -86,13 +87,12 @@ def display_parameter_survey():
|
|
| 86 |
console.log("Submission Data:", data);
|
| 87 |
|
| 88 |
fetch('/submit', {{
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
}}
|
| 96 |
}});
|
| 97 |
</script>
|
| 98 |
"""
|
|
|
|
| 5 |
from gradio_toggle import Toggle
|
| 6 |
import json
|
| 7 |
import yaml
|
| 8 |
+
from fastapi import FastAPI
|
| 9 |
+
|
| 10 |
+
app = FastAPI()
|
| 11 |
|
| 12 |
from process_data import parse_survey_stack_parameters, parse_survey_stack_data, process_specifications
|
| 13 |
|
| 14 |
global parsed_input_data
|
| 15 |
global original_outputs, yaml_outputs
|
| 16 |
|
| 17 |
+
@app.post("/submit")
|
| 18 |
+
def submit_data(data: dict):
|
| 19 |
+
print("Received submission data:", data)
|
| 20 |
+
return {"message": "Data processed successfully!"}
|
| 21 |
|
| 22 |
+
def process_survey(button_type, survey_submission_ID):
|
| 23 |
if button_type == 'data':
|
| 24 |
survey_id = "671fc52152e3225d7de349e6"
|
| 25 |
|
|
|
|
| 64 |
except Exception as e:
|
| 65 |
return f"An error occurred while fetching the survey data: {e}"
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
def display_parameter_survey():
|
| 69 |
base_url = "https://app.surveystack.io/groups/"
|
|
|
|
| 87 |
console.log("Submission Data:", data);
|
| 88 |
|
| 89 |
fetch('/submit', {{
|
| 90 |
+
method: 'POST',
|
| 91 |
+
headers: {{
|
| 92 |
+
'Content-Type': 'application/json'
|
| 93 |
+
}},
|
| 94 |
+
body: JSON.stringify({{submission_id: data}})
|
| 95 |
+
}});
|
|
|
|
| 96 |
}});
|
| 97 |
</script>
|
| 98 |
"""
|