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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
total_number_pages = 5
|
| 6 |
+
placeholder_buttons = None
|
| 7 |
+
|
| 8 |
+
Q1_radio_options = ["Pineapple","Cheese","Pepperoni","Mushroom","Sausage","Other"]
|
| 9 |
+
Q2_radio_options = ["Football","Baseball","Basketball","Soccer","Golf","Other"]
|
| 10 |
+
Q3_radio_options = ["0-10","11-20","21-30","31-40","41-50","51-60","60+"]
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# Function that records radio element changes
|
| 14 |
+
def radio_change(element, state, key):
|
| 15 |
+
st.session_state[state] = element.index(st.session_state[key]) # Setting previously selected option
|
| 16 |
+
# Function that disables the last button while data is uploaded to IPFS
|
| 17 |
+
def button_disable():
|
| 18 |
+
st.session_state['disabled'] = True
|
| 19 |
+
|
| 20 |
+
st.set_page_config(page_title='IPFS-Based Survey',)
|
| 21 |
+
st.title('Test Survey')
|
| 22 |
+
|
| 23 |
+
st.markdown("<style>.row-widget.stButton {text-align: center;}</style>", unsafe_allow_html=True)
|
| 24 |
+
st.markdown("<style>.big-font {font-size:24px;}</style>", unsafe_allow_html=True)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
if "current_page" not in st.session_state:
|
| 28 |
+
st.session_state["current_page"] = 1
|
| 29 |
+
st.session_state["Q1"] = None
|
| 30 |
+
st.session_state["Q2"] = None
|
| 31 |
+
st.session_state["Q3"] = None
|
| 32 |
+
st.session_state["disabled"] = False
|
| 33 |
+
|
| 34 |
+
# Page 1; Video
|
| 35 |
+
if st.session_state["current_page"] == 1:
|
| 36 |
+
|
| 37 |
+
st.markdown("""<p class="big-font">I hope this works :|</p>""", unsafe_allow_html=True)
|
| 38 |
+
st.video("https://www.youtube.com/watch?v=aJb6Dov0jlM")
|
| 39 |
+
|
| 40 |
+
placeholder = st.empty()
|
| 41 |
+
|
| 42 |
+
if st.button('Next', key='next_button_page_1'):
|
| 43 |
+
all_answered = True
|
| 44 |
+
if all_answered:
|
| 45 |
+
st.session_state["current_page"] += 1
|
| 46 |
+
st.rerun()
|
| 47 |
+
else:
|
| 48 |
+
with placeholder.container():
|
| 49 |
+
st.warning("Please answer all the questions on this page.", icon="⚠️")
|
| 50 |
+
|
| 51 |
+
st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
elif st.session_state["current_page"] == 2:
|
| 55 |
+
|
| 56 |
+
st.radio(label = "What is your favorite type of pizza?",
|
| 57 |
+
options = Q1_radio_options,
|
| 58 |
+
index = None if st.session_state["Q1"] == None else st.session_state["Q1"],
|
| 59 |
+
key = 'Q1_radio',
|
| 60 |
+
on_change = radio_change,
|
| 61 |
+
args = (Q1_radio_options, "Q1", "Q1_radio",))
|
| 62 |
+
|
| 63 |
+
# The code below changes the font size of the above radio's label.
|
| 64 |
+
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
placeholder = st.empty()
|
| 68 |
+
|
| 69 |
+
col1, col2 = st.columns(2)
|
| 70 |
+
with col1:
|
| 71 |
+
if st.button('Back'):
|
| 72 |
+
st.session_state["current_page"] -= 1
|
| 73 |
+
st.rerun()
|
| 74 |
+
with col2:
|
| 75 |
+
if st.button('Next', key='next_button_page_2'):
|
| 76 |
+
all_answered = True
|
| 77 |
+
if st.session_state["Q1"] == None:
|
| 78 |
+
all_answered = False
|
| 79 |
+
if all_answered:
|
| 80 |
+
st.session_state["current_page"] += 1
|
| 81 |
+
st.rerun()
|
| 82 |
+
else:
|
| 83 |
+
with placeholder.container():
|
| 84 |
+
st.warning("Please answer all the questions on this page.", icon="⚠️")
|
| 85 |
+
|
| 86 |
+
st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
elif st.session_state["current_page"] == 3:
|
| 90 |
+
|
| 91 |
+
st.radio(label = "Favorite Sport?",
|
| 92 |
+
options = Q2_radio_options,
|
| 93 |
+
index = None if st.session_state["Q2"] == None else st.session_state["Q2"],
|
| 94 |
+
key = 'Q2_radio',
|
| 95 |
+
on_change = radio_change,
|
| 96 |
+
args = (Q2_radio_options, "Q2", "Q2_radio",))
|
| 97 |
+
|
| 98 |
+
# The code below changes the font size of the above radio's label.
|
| 99 |
+
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
st.radio(label = "How old are you",
|
| 103 |
+
options = Q3_radio_options,
|
| 104 |
+
index = None if st.session_state["Q3"] == None else st.session_state["Q3"],
|
| 105 |
+
key = 'Q3_radio',
|
| 106 |
+
on_change = radio_change,
|
| 107 |
+
args = (Q3_radio_options, "Q3", "Q3_radio",))
|
| 108 |
+
|
| 109 |
+
# The code below changes the font size of the above radio's label.
|
| 110 |
+
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
placeholder = st.empty()
|
| 114 |
+
|
| 115 |
+
col1, col2 = st.columns(2)
|
| 116 |
+
with col1:
|
| 117 |
+
if st.button('Back'):
|
| 118 |
+
st.session_state["current_page"] -= 1
|
| 119 |
+
st.rerun()
|
| 120 |
+
with col2:
|
| 121 |
+
if st.button('Next', key='next_button_page_3'):
|
| 122 |
+
all_answered = True
|
| 123 |
+
if st.session_state["Q2"] == None:
|
| 124 |
+
all_answered = False
|
| 125 |
+
if st.session_state["Q3"] == None:
|
| 126 |
+
all_answered = False
|
| 127 |
+
if all_answered:
|
| 128 |
+
st.session_state["current_page"] += 1
|
| 129 |
+
st.rerun()
|
| 130 |
+
else:
|
| 131 |
+
with placeholder.container():
|
| 132 |
+
st.warning("Please answer all the questions on this page.", icon="⚠️")
|
| 133 |
+
|
| 134 |
+
st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
elif st.session_state["current_page"] == 4:
|
| 138 |
+
|
| 139 |
+
placeholder = st.empty()
|
| 140 |
+
|
| 141 |
+
col1, col2 = st.columns(2)
|
| 142 |
+
with col1:
|
| 143 |
+
if st.button('Back'):
|
| 144 |
+
st.session_state["current_page"] -= 1
|
| 145 |
+
st.rerun()
|
| 146 |
+
with col2:
|
| 147 |
+
if st.button('Next', key='next_button_page_4'):
|
| 148 |
+
all_answered = True
|
| 149 |
+
if all_answered:
|
| 150 |
+
st.session_state["current_page"] += 1
|
| 151 |
+
st.rerun()
|
| 152 |
+
else:
|
| 153 |
+
with placeholder.container():
|
| 154 |
+
st.warning("Please answer all the questions on this page.", icon="⚠️")
|
| 155 |
+
|
| 156 |
+
st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
elif st.session_state["current_page"] == 5:
|
| 160 |
+
|
| 161 |
+
placeholder = st.empty()
|
| 162 |
+
|
| 163 |
+
col1, col2 = st.columns(2)
|
| 164 |
+
with col1:
|
| 165 |
+
if st.button('Back'):
|
| 166 |
+
st.session_state["current_page"] -= 1
|
| 167 |
+
st.rerun()
|
| 168 |
+
with col2:
|
| 169 |
+
if st.button('Next', key='next_button_page_undefined'):
|
| 170 |
+
all_answered = True
|
| 171 |
+
if all_answered:
|
| 172 |
+
st.session_state["current_page"] += 1
|
| 173 |
+
st.rerun()
|
| 174 |
+
else:
|
| 175 |
+
with placeholder.container():
|
| 176 |
+
st.warning("Please answer all the questions on this page.", icon="⚠️")
|
| 177 |
+
|
| 178 |
+
st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
|
| 179 |
+
|
| 180 |
+
|