Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,32 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from urllib.parse import urljoin
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
def display_survey(survey_id):
|
| 5 |
base_url = "https://app.surveystack.io/groups/"
|
| 6 |
-
group_id = "5e95e368fbbf75000146a006" #
|
| 7 |
|
| 8 |
# Construct the full URL using urljoin to ensure proper formatting
|
| 9 |
survey_url = urljoin(base_url, f"{group_id}/surveys/{survey_id}/submissions/new")
|
|
@@ -15,13 +38,24 @@ def display_survey(survey_id):
|
|
| 15 |
|
| 16 |
with gr.Blocks() as app:
|
| 17 |
with gr.Row():
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
| 20 |
|
| 21 |
with gr.Row():
|
| 22 |
survey_output = gr.HTML()
|
| 23 |
|
| 24 |
submit_button.click(fn=display_survey, inputs=surveyID_input, outputs=survey_output)
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
app.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
from urllib.parse import urljoin
|
| 4 |
|
| 5 |
+
def process_survey(survey_id, submission_id):
|
| 6 |
+
base_url = "https://app.surveystack.io/api/submissions"
|
| 7 |
+
params = {
|
| 8 |
+
"survey": survey_id,
|
| 9 |
+
"match": f'{{"_id":{{"$oid":"{submission_id}"}}}}'
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
encoded_params = urlencode(params)
|
| 13 |
+
|
| 14 |
+
survey_url = urljoin(base_url, encoded_params)
|
| 15 |
+
print(survey_url)
|
| 16 |
+
|
| 17 |
+
try:
|
| 18 |
+
response = requests.get(survey_url)
|
| 19 |
+
response.raise_for_status()
|
| 20 |
+
data = response.json()
|
| 21 |
+
return data
|
| 22 |
+
|
| 23 |
+
except Exception as e:
|
| 24 |
+
return f"An error occurred while fetching the survey data: {e}"
|
| 25 |
+
|
| 26 |
+
|
| 27 |
def display_survey(survey_id):
|
| 28 |
base_url = "https://app.surveystack.io/groups/"
|
| 29 |
+
group_id = "5e95e368fbbf75000146a006" # Group ID "Our-Sci"
|
| 30 |
|
| 31 |
# Construct the full URL using urljoin to ensure proper formatting
|
| 32 |
survey_url = urljoin(base_url, f"{group_id}/surveys/{survey_id}/submissions/new")
|
|
|
|
| 38 |
|
| 39 |
with gr.Blocks() as app:
|
| 40 |
with gr.Row():
|
| 41 |
+
with gr.Column():
|
| 42 |
+
surveyID_input = gr.Textbox(label="Enter SurveyStack Survey ID")
|
| 43 |
+
with gr.Column():
|
| 44 |
+
submit_button = gr.Button("Load Survey")
|
| 45 |
|
| 46 |
with gr.Row():
|
| 47 |
survey_output = gr.HTML()
|
| 48 |
|
| 49 |
submit_button.click(fn=display_survey, inputs=surveyID_input, outputs=survey_output)
|
| 50 |
|
| 51 |
+
survey_submission_ID = gr.Textbox(label="Before submitting your surveystack survey, PLEASE record your submission ID. Type it here.")
|
| 52 |
+
|
| 53 |
+
hf_submit_button = gr.Button("Parse Input Data")
|
| 54 |
+
|
| 55 |
+
get_survey_back = gr.HTML()
|
| 56 |
+
|
| 57 |
+
submit_button.click(fn=process_survey, inputs=[surveyID_input, survey_submission_ID], outputs=get_survey_back)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
|
| 61 |
app.launch()
|