Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,9 +3,15 @@ import requests
|
|
| 3 |
import json
|
| 4 |
import web3
|
| 5 |
|
| 6 |
-
total_number_pages =
|
| 7 |
placeholder_buttons = None
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
# Function that records radio element changes
|
|
@@ -25,7 +31,7 @@ def answer_change(state, key):
|
|
| 25 |
st.session_state[state] = st.session_state[key]
|
| 26 |
|
| 27 |
st.set_page_config(page_title='IPFS-Based Survey',)
|
| 28 |
-
st.title('')
|
| 29 |
|
| 30 |
st.markdown("<style>.row-widget.stButton {text-align: center;}</style>", unsafe_allow_html=True)
|
| 31 |
st.markdown("<style>.big-font {font-size:24px;}</style>", unsafe_allow_html=True)
|
|
@@ -36,16 +42,273 @@ if "current_page" not in st.session_state:
|
|
| 36 |
st.session_state["Q1"] = None
|
| 37 |
st.session_state["Q2"] = None
|
| 38 |
st.session_state["Q3"] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
st.session_state["disabled"] = False
|
| 40 |
|
| 41 |
# Page 1; Video
|
| 42 |
if st.session_state["current_page"] == 1:
|
| 43 |
|
| 44 |
-
st.markdown("""<p class="big-font"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
st.video("https://www.youtube.com/watch?v=U06jlgpMtQs")
|
| 47 |
st.image("http://t3.gstatic.com/licensed-image?q=tbn:ANd9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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
placeholder = st.empty()
|
| 50 |
|
| 51 |
col1, col2 = st.columns(2)
|
|
|
|
| 3 |
import json
|
| 4 |
import web3
|
| 5 |
|
| 6 |
+
total_number_pages = 7
|
| 7 |
placeholder_buttons = None
|
| 8 |
|
| 9 |
+
Q2_radio_options = ["Yes","No"]
|
| 10 |
+
Q4_radio_options = ["Option 1 multi","Option 2 multi"]
|
| 11 |
+
Q5_radio_options = ["Option 1 Radio","Option 2 Radio"]
|
| 12 |
+
Q6_radio_options = ["Green","Red","Blue","Yellow"]
|
| 13 |
+
Q7_radio_options = ["Yes","No","Ur dumb"]
|
| 14 |
+
Q10_radio_options = ["IDK","Of Course","STFU!!!!!","Inner demons"]
|
| 15 |
|
| 16 |
|
| 17 |
# Function that records radio element changes
|
|
|
|
| 31 |
st.session_state[state] = st.session_state[key]
|
| 32 |
|
| 33 |
st.set_page_config(page_title='IPFS-Based Survey',)
|
| 34 |
+
st.title('Newest Test')
|
| 35 |
|
| 36 |
st.markdown("<style>.row-widget.stButton {text-align: center;}</style>", unsafe_allow_html=True)
|
| 37 |
st.markdown("<style>.big-font {font-size:24px;}</style>", unsafe_allow_html=True)
|
|
|
|
| 42 |
st.session_state["Q1"] = None
|
| 43 |
st.session_state["Q2"] = None
|
| 44 |
st.session_state["Q3"] = None
|
| 45 |
+
st.session_state["Q4"] = None
|
| 46 |
+
st.session_state["Q5"] = None
|
| 47 |
+
st.session_state["Q6"] = None
|
| 48 |
+
st.session_state["Q7"] = None
|
| 49 |
+
st.session_state["Q8"] = None
|
| 50 |
+
st.session_state["Q9"] = None
|
| 51 |
+
st.session_state["Q10"] = None
|
| 52 |
st.session_state["disabled"] = False
|
| 53 |
|
| 54 |
# Page 1; Video
|
| 55 |
if st.session_state["current_page"] == 1:
|
| 56 |
|
| 57 |
+
st.markdown("""<p class="big-font">This is a Test of the latest version of the survey builder Tool</p>""", unsafe_allow_html=True)
|
| 58 |
+
|
| 59 |
+
st.video("https://www.youtube.com/watch?v=aJb6Dov0jlM")
|
| 60 |
+
st.text_area(label = "This is a text Question and should allow any text input. This should appear on the first page.",
|
| 61 |
+
value= "" if st.session_state["Q1"] == None else st.session_state["Q1"],
|
| 62 |
+
key = 'Q1_text',
|
| 63 |
+
on_change = answer_change,
|
| 64 |
+
args = ( "Q1", "Q1_text",))
|
| 65 |
+
|
| 66 |
+
# The code below changes the font size of the above radio's label.
|
| 67 |
+
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
st.selectbox(label = "Selecting Box",
|
| 71 |
+
options = Q2_radio_options,
|
| 72 |
+
index = None if st.session_state["Q2"] == None else st.session_state["Q2"],
|
| 73 |
+
key = 'Q2_radio',
|
| 74 |
+
on_change = radio_change,
|
| 75 |
+
args = (Q2_radio_options, "Q2", "Q2_radio",))
|
| 76 |
+
|
| 77 |
+
# The code below changes the font size of the above radio's label.
|
| 78 |
+
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
placeholder = st.empty()
|
| 82 |
+
|
| 83 |
+
if st.button('Next', key='next_button_page_1'):
|
| 84 |
+
all_answered = True
|
| 85 |
+
if st.session_state["Q1"] == None:
|
| 86 |
+
all_answered = False
|
| 87 |
+
if st.session_state["Q2"] == None:
|
| 88 |
+
all_answered = False
|
| 89 |
+
if all_answered:
|
| 90 |
+
st.session_state["current_page"] += 1
|
| 91 |
+
st.rerun()
|
| 92 |
+
else:
|
| 93 |
+
with placeholder.container():
|
| 94 |
+
st.warning("Please answer all the questions on this page.", icon="⚠️")
|
| 95 |
+
|
| 96 |
+
st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
elif st.session_state["current_page"] == 2:
|
| 100 |
|
|
|
|
| 101 |
st.image("http://t3.gstatic.com/licensed-image?q=tbn:ANd9GcTF_OQ101nRiHil4w5295pqLf5M8axplaqmwCthHGgdqlu21bMsP8VmMdl4zkPUnW2pgcNWEWJyl-Y46P1J_d8")
|
| 102 |
+
st.slider(label="This is a slider question that allows a numeric input between two numbers. This should appear on the second page.",min_value=0,max_value=10,
|
| 103 |
+
value= 5 if st.session_state["Q3"] == None else st.session_state["Q3"],
|
| 104 |
+
key = "Q3_slider",
|
| 105 |
+
on_change = answer_change,
|
| 106 |
+
args = ("Q3", "Q3_slider",))
|
| 107 |
+
# The code below changes the font size of the above radio's label.
|
| 108 |
+
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
st.multiselect(label = "This is a multiselect question where you can select multiple answers. This should appear on the second page.",
|
| 112 |
+
default = None if st.session_state["Q4"] == None else st.session_state["Q4"],
|
| 113 |
+
options = Q4_radio_options,
|
| 114 |
+
key = 'Q4_multi',
|
| 115 |
+
on_change = multi_change,
|
| 116 |
+
args = (Q4_radio_options, "Q4", "Q4_multi",))
|
| 117 |
+
|
| 118 |
+
# The code below changes the font size of the above radio's label.
|
| 119 |
+
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
placeholder = st.empty()
|
| 123 |
+
|
| 124 |
+
col1, col2 = st.columns(2)
|
| 125 |
+
with col1:
|
| 126 |
+
if st.button('Back'):
|
| 127 |
+
st.session_state["current_page"] -= 1
|
| 128 |
+
st.rerun()
|
| 129 |
+
with col2:
|
| 130 |
+
if st.button('Next'):
|
| 131 |
+
all_answered = True
|
| 132 |
+
if st.session_state["Q3"] == None:
|
| 133 |
+
all_answered = False
|
| 134 |
+
if st.session_state["Q4"] == None:
|
| 135 |
+
all_answered = False
|
| 136 |
+
if all_answered:
|
| 137 |
+
st.session_state["current_page"] += 1
|
| 138 |
+
st.rerun()
|
| 139 |
+
else:
|
| 140 |
+
with placeholder.container():
|
| 141 |
+
st.warning("Please answer all the questions on this page.", icon="⚠️")
|
| 142 |
+
|
| 143 |
+
st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
elif st.session_state["current_page"] == 3:
|
| 147 |
+
|
| 148 |
+
st.markdown("""<p>The follwing questions are about my life</p>""", unsafe_allow_html=True)
|
| 149 |
+
st.radio(label = "This is a multiple choice question where you can choose one of the following. This should appear on the third page.",
|
| 150 |
+
options = Q5_radio_options,
|
| 151 |
+
index = None if st.session_state["Q5"] == None else st.session_state["Q5"],
|
| 152 |
+
key = 'Q5_radio',
|
| 153 |
+
on_change = radio_change,
|
| 154 |
+
args = (Q5_radio_options, "Q5", "Q5_radio",))
|
| 155 |
+
|
| 156 |
+
# The code below changes the font size of the above radio's label.
|
| 157 |
+
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
st.radio(label = "Fav Color?",
|
| 161 |
+
options = Q6_radio_options,
|
| 162 |
+
index = None if st.session_state["Q6"] == None else st.session_state["Q6"],
|
| 163 |
+
key = 'Q6_radio',
|
| 164 |
+
on_change = radio_change,
|
| 165 |
+
args = (Q6_radio_options, "Q6", "Q6_radio",))
|
| 166 |
+
|
| 167 |
+
# The code below changes the font size of the above radio's label.
|
| 168 |
+
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
st.multiselect(label = "Party Time",
|
| 172 |
+
default = None if st.session_state["Q7"] == None else st.session_state["Q7"],
|
| 173 |
+
options = Q7_radio_options,
|
| 174 |
+
key = 'Q7_multi',
|
| 175 |
+
on_change = multi_change,
|
| 176 |
+
args = (Q7_radio_options, "Q7", "Q7_multi",))
|
| 177 |
+
|
| 178 |
+
# The code below changes the font size of the above radio's label.
|
| 179 |
+
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
placeholder = st.empty()
|
| 183 |
+
|
| 184 |
+
col1, col2 = st.columns(2)
|
| 185 |
+
with col1:
|
| 186 |
+
if st.button('Back'):
|
| 187 |
+
st.session_state["current_page"] -= 1
|
| 188 |
+
st.rerun()
|
| 189 |
+
with col2:
|
| 190 |
+
if st.button('Next'):
|
| 191 |
+
all_answered = True
|
| 192 |
+
if st.session_state["Q5"] == None:
|
| 193 |
+
all_answered = False
|
| 194 |
+
if st.session_state["Q6"] == None:
|
| 195 |
+
all_answered = False
|
| 196 |
+
if st.session_state["Q7"] == None:
|
| 197 |
+
all_answered = False
|
| 198 |
+
if all_answered:
|
| 199 |
+
st.session_state["current_page"] += 1
|
| 200 |
+
st.rerun()
|
| 201 |
+
else:
|
| 202 |
+
with placeholder.container():
|
| 203 |
+
st.warning("Please answer all the questions on this page.", icon="⚠️")
|
| 204 |
+
|
| 205 |
+
st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
elif st.session_state["current_page"] == 4:
|
| 209 |
+
|
| 210 |
+
st.slider(label="Happiness Scale",min_value=0,max_value=100,
|
| 211 |
+
value= 50 if st.session_state["Q8"] == None else st.session_state["Q8"],
|
| 212 |
+
key = "Q8_slider",
|
| 213 |
+
on_change = answer_change,
|
| 214 |
+
args = ("Q8", "Q8_slider",))
|
| 215 |
+
# The code below changes the font size of the above radio's label.
|
| 216 |
+
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
st.text_area(label = "Why are you this happy/unhappy?",
|
| 220 |
+
value= "" if st.session_state["Q9"] == None else st.session_state["Q9"],
|
| 221 |
+
key = 'Q9_text',
|
| 222 |
+
on_change = answer_change,
|
| 223 |
+
args = ( "Q9", "Q9_text",))
|
| 224 |
+
|
| 225 |
+
# The code below changes the font size of the above radio's label.
|
| 226 |
+
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
placeholder = st.empty()
|
| 230 |
+
|
| 231 |
+
col1, col2 = st.columns(2)
|
| 232 |
+
with col1:
|
| 233 |
+
if st.button('Back'):
|
| 234 |
+
st.session_state["current_page"] -= 1
|
| 235 |
+
st.rerun()
|
| 236 |
+
with col2:
|
| 237 |
+
if st.button('Next'):
|
| 238 |
+
all_answered = True
|
| 239 |
+
if st.session_state["Q8"] == None:
|
| 240 |
+
all_answered = False
|
| 241 |
+
if st.session_state["Q9"] == None:
|
| 242 |
+
all_answered = False
|
| 243 |
+
if all_answered:
|
| 244 |
+
st.session_state["current_page"] += 1
|
| 245 |
+
st.rerun()
|
| 246 |
+
else:
|
| 247 |
+
with placeholder.container():
|
| 248 |
+
st.warning("Please answer all the questions on this page.", icon="⚠️")
|
| 249 |
+
|
| 250 |
+
st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
elif st.session_state["current_page"] == 5:
|
| 254 |
+
|
| 255 |
+
placeholder = st.empty()
|
| 256 |
+
|
| 257 |
+
col1, col2 = st.columns(2)
|
| 258 |
+
with col1:
|
| 259 |
+
if st.button('Back'):
|
| 260 |
+
st.session_state["current_page"] -= 1
|
| 261 |
+
st.rerun()
|
| 262 |
+
with col2:
|
| 263 |
+
if st.button('Next'):
|
| 264 |
+
all_answered = True
|
| 265 |
+
if all_answered:
|
| 266 |
+
st.session_state["current_page"] += 1
|
| 267 |
+
st.rerun()
|
| 268 |
+
else:
|
| 269 |
+
with placeholder.container():
|
| 270 |
+
st.warning("Please answer all the questions on this page.", icon="⚠️")
|
| 271 |
+
|
| 272 |
+
st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
elif st.session_state["current_page"] == 6:
|
| 276 |
+
|
| 277 |
+
st.radio(label = "I like cheese?",
|
| 278 |
+
options = Q10_radio_options,
|
| 279 |
+
index = None if st.session_state["Q10"] == None else st.session_state["Q10"],
|
| 280 |
+
key = 'Q10_radio',
|
| 281 |
+
on_change = radio_change,
|
| 282 |
+
args = (Q10_radio_options, "Q10", "Q10_radio",))
|
| 283 |
+
|
| 284 |
+
# The code below changes the font size of the above radio's label.
|
| 285 |
+
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
placeholder = st.empty()
|
| 289 |
+
|
| 290 |
+
col1, col2 = st.columns(2)
|
| 291 |
+
with col1:
|
| 292 |
+
if st.button('Back'):
|
| 293 |
+
st.session_state["current_page"] -= 1
|
| 294 |
+
st.rerun()
|
| 295 |
+
with col2:
|
| 296 |
+
if st.button('Next'):
|
| 297 |
+
all_answered = True
|
| 298 |
+
if st.session_state["Q10"] == None:
|
| 299 |
+
all_answered = False
|
| 300 |
+
if all_answered:
|
| 301 |
+
st.session_state["current_page"] += 1
|
| 302 |
+
st.rerun()
|
| 303 |
+
else:
|
| 304 |
+
with placeholder.container():
|
| 305 |
+
st.warning("Please answer all the questions on this page.", icon="⚠️")
|
| 306 |
+
|
| 307 |
+
st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
elif st.session_state["current_page"] == 7:
|
| 311 |
+
|
| 312 |
placeholder = st.empty()
|
| 313 |
|
| 314 |
col1, col2 = st.columns(2)
|