Spaces:
Build error
Build error
Add app.py
Browse files
app.py
CHANGED
|
@@ -161,11 +161,15 @@ def submission(survey_data):
|
|
| 161 |
upload_to_blockchain(ipfs_hash)
|
| 162 |
st.info(f'The IPFS hash is: {ipfs_hash}', icon="ℹ️")
|
| 163 |
|
| 164 |
-
total_number_pages =
|
| 165 |
placeholder_buttons = None
|
| 166 |
|
| 167 |
-
Q1_radio_options = ["
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
|
| 170 |
|
| 171 |
# Function that records radio element changes
|
|
@@ -185,7 +189,7 @@ def answer_change(state, key):
|
|
| 185 |
st.session_state[state] = st.session_state[key]
|
| 186 |
|
| 187 |
st.set_page_config(page_title='IPFS-Based Survey',)
|
| 188 |
-
st.title('
|
| 189 |
|
| 190 |
st.markdown("<style>.row-widget.stButton {text-align: center;}</style>", unsafe_allow_html=True)
|
| 191 |
st.markdown("<style>.big-font {font-size:24px;}</style>", unsafe_allow_html=True)
|
|
@@ -196,14 +200,17 @@ if "current_page" not in st.session_state:
|
|
| 196 |
st.session_state["Q1"] = None
|
| 197 |
st.session_state["Q2"] = None
|
| 198 |
st.session_state["Q3"] = None
|
|
|
|
|
|
|
|
|
|
| 199 |
st.session_state["disabled"] = False
|
| 200 |
|
| 201 |
# Page 1; Video
|
| 202 |
if st.session_state["current_page"] == 1:
|
| 203 |
|
| 204 |
-
st.markdown("""<p style='font-size:18px ;'>
|
| 205 |
|
| 206 |
-
st.radio(label = "
|
| 207 |
options = Q1_radio_options,
|
| 208 |
index = None if st.session_state["Q1"] == None else st.session_state["Q1"],
|
| 209 |
key = 'Q1_radio',
|
|
@@ -213,23 +220,72 @@ if st.session_state["current_page"] == 1:
|
|
| 213 |
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 214 |
|
| 215 |
|
| 216 |
-
st.
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
|
|
|
| 221 |
|
| 222 |
-
st.markdown("""<style> div[class*="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
|
| 225 |
placeholder = st.empty()
|
| 226 |
|
| 227 |
-
if st.button('Next'
|
| 228 |
all_answered = True
|
| 229 |
if st.session_state["Q1"] == None or st.session_state["Q1"] == []:
|
| 230 |
all_answered = False
|
| 231 |
if st.session_state["Q2"] == None or st.session_state["Q2"] == []:
|
| 232 |
all_answered = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
if all_answered:
|
| 234 |
st.session_state["current_page"] += 1
|
| 235 |
st.rerun()
|
|
@@ -240,41 +296,7 @@ if st.session_state["current_page"] == 1:
|
|
| 240 |
st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
|
| 241 |
|
| 242 |
|
| 243 |
-
elif st.session_state["current_page"] == 2:
|
| 244 |
-
|
| 245 |
-
st.selectbox(label = "Was that a good joke?",
|
| 246 |
-
options = Q3_radio_options,
|
| 247 |
-
index = None if st.session_state["Q3"] == None else st.session_state["Q3"],
|
| 248 |
-
key = 'Q3_radio',
|
| 249 |
-
on_change = radio_change,
|
| 250 |
-
args = (Q3_radio_options, "Q3", "Q3_radio",))
|
| 251 |
-
|
| 252 |
-
st.markdown("""<style> div[class*="stSelectbox"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 253 |
-
|
| 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 st.session_state["Q3"] == None or st.session_state["Q3"] == []:
|
| 266 |
-
all_answered = False
|
| 267 |
-
if all_answered:
|
| 268 |
-
st.session_state["current_page"] += 1
|
| 269 |
-
st.rerun()
|
| 270 |
-
else:
|
| 271 |
-
with placeholder.container():
|
| 272 |
-
st.warning("Please answer all the questions on this page.", icon="⚠️")
|
| 273 |
-
|
| 274 |
-
st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
elif st.session_state["current_page"] == 3: # Last Page
|
| 278 |
st.markdown('<p class="big-font">Thank you for participating! <br> Click on the button below to submit your answers. </p>', unsafe_allow_html=True)
|
| 279 |
st.button('Submit Responses', disabled = st.session_state["disabled"], on_click = button_disable)
|
| 280 |
if st.session_state["disabled"]:
|
|
@@ -284,12 +306,16 @@ elif st.session_state["current_page"] == 3: # Last Page
|
|
| 284 |
"Q1": Q1_radio_options[st.session_state["Q1"]],
|
| 285 |
"Q2": st.session_state["Q2"],
|
| 286 |
"Q3": Q3_radio_options[st.session_state["Q3"]],
|
|
|
|
|
|
|
|
|
|
| 287 |
}
|
| 288 |
submission(response)
|
| 289 |
except Exception as e:
|
| 290 |
print(e)
|
| 291 |
st.error(f'An error ocurred. Here is the error message: {e}', icon="🚨")
|
| 292 |
|
|
|
|
| 293 |
|
| 294 |
if st.button('Back'):
|
| 295 |
st.session_state["current_page"] -= 1
|
|
|
|
| 161 |
upload_to_blockchain(ipfs_hash)
|
| 162 |
st.info(f'The IPFS hash is: {ipfs_hash}', icon="ℹ️")
|
| 163 |
|
| 164 |
+
total_number_pages = 2
|
| 165 |
placeholder_buttons = None
|
| 166 |
|
| 167 |
+
Q1_radio_options = ["Yippee","No"]
|
| 168 |
+
Q2_radio_options = ["1","gsdjjij"]
|
| 169 |
+
Q3_radio_options = ["N/A", "Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"]
|
| 170 |
+
Q4_radio_options = ["N/A", "Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"]
|
| 171 |
+
Q5_radio_options = ["N/A", "Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"]
|
| 172 |
+
Q6_radio_options = ["N/A", "Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"]
|
| 173 |
|
| 174 |
|
| 175 |
# Function that records radio element changes
|
|
|
|
| 189 |
st.session_state[state] = st.session_state[key]
|
| 190 |
|
| 191 |
st.set_page_config(page_title='IPFS-Based Survey',)
|
| 192 |
+
st.title('')
|
| 193 |
|
| 194 |
st.markdown("<style>.row-widget.stButton {text-align: center;}</style>", unsafe_allow_html=True)
|
| 195 |
st.markdown("<style>.big-font {font-size:24px;}</style>", unsafe_allow_html=True)
|
|
|
|
| 200 |
st.session_state["Q1"] = None
|
| 201 |
st.session_state["Q2"] = None
|
| 202 |
st.session_state["Q3"] = None
|
| 203 |
+
st.session_state["Q4"] = None
|
| 204 |
+
st.session_state["Q5"] = None
|
| 205 |
+
st.session_state["Q6"] = None
|
| 206 |
st.session_state["disabled"] = False
|
| 207 |
|
| 208 |
# Page 1; Video
|
| 209 |
if st.session_state["current_page"] == 1:
|
| 210 |
|
| 211 |
+
st.markdown("""<p style='font-size:18px ;'></p>""", unsafe_allow_html=True)
|
| 212 |
|
| 213 |
+
st.radio(label = "Hello",
|
| 214 |
options = Q1_radio_options,
|
| 215 |
index = None if st.session_state["Q1"] == None else st.session_state["Q1"],
|
| 216 |
key = 'Q1_radio',
|
|
|
|
| 220 |
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 221 |
|
| 222 |
|
| 223 |
+
st.multiselect(label = "WHATS",
|
| 224 |
+
default = None if st.session_state["Q2"] == None else st.session_state["Q2"],
|
| 225 |
+
options = Q2_radio_options,
|
| 226 |
+
key = 'Q2_multi',
|
| 227 |
+
on_change = multi_change,
|
| 228 |
+
args = (Q2_radio_options, "Q2", "Q2_multi",))
|
| 229 |
|
| 230 |
+
st.markdown("""<style> div[class*="stMulti"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
st.radio(label = "Miami?", # Likert
|
| 234 |
+
options = Q3_radio_options,
|
| 235 |
+
index = None if st.session_state["Q3"] == None else st.session_state["Q3"],
|
| 236 |
+
key = 'Q3_radio',
|
| 237 |
+
on_change = radio_change,
|
| 238 |
+
args = (Q3_radio_options, "Q3", "Q3_radio",))
|
| 239 |
+
|
| 240 |
+
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
st.radio(label = "People", # Likert
|
| 244 |
+
options = Q4_radio_options,
|
| 245 |
+
index = None if st.session_state["Q4"] == None else st.session_state["Q4"],
|
| 246 |
+
key = 'Q4_radio',
|
| 247 |
+
on_change = radio_change,
|
| 248 |
+
args = (Q4_radio_options, "Q4", "Q4_radio",))
|
| 249 |
+
|
| 250 |
+
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
st.radio(label = "Life", # Likert
|
| 254 |
+
options = Q5_radio_options,
|
| 255 |
+
index = None if st.session_state["Q5"] == None else st.session_state["Q5"],
|
| 256 |
+
key = 'Q5_radio',
|
| 257 |
+
on_change = radio_change,
|
| 258 |
+
args = (Q5_radio_options, "Q5", "Q5_radio",))
|
| 259 |
+
|
| 260 |
+
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
st.radio(label = "Wods", # Likert
|
| 264 |
+
options = Q6_radio_options,
|
| 265 |
+
index = None if st.session_state["Q6"] == None else st.session_state["Q6"],
|
| 266 |
+
key = 'Q6_radio',
|
| 267 |
+
on_change = radio_change,
|
| 268 |
+
args = (Q6_radio_options, "Q6", "Q6_radio",))
|
| 269 |
+
|
| 270 |
+
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 271 |
|
| 272 |
|
| 273 |
placeholder = st.empty()
|
| 274 |
|
| 275 |
+
if st.button('Next'):
|
| 276 |
all_answered = True
|
| 277 |
if st.session_state["Q1"] == None or st.session_state["Q1"] == []:
|
| 278 |
all_answered = False
|
| 279 |
if st.session_state["Q2"] == None or st.session_state["Q2"] == []:
|
| 280 |
all_answered = False
|
| 281 |
+
if st.session_state["Q3"] == None or st.session_state["Q3"] == []:
|
| 282 |
+
all_answered = False
|
| 283 |
+
if st.session_state["Q4"] == None or st.session_state["Q4"] == []:
|
| 284 |
+
all_answered = False
|
| 285 |
+
if st.session_state["Q5"] == None or st.session_state["Q5"] == []:
|
| 286 |
+
all_answered = False
|
| 287 |
+
if st.session_state["Q6"] == None or st.session_state["Q6"] == []:
|
| 288 |
+
all_answered = False
|
| 289 |
if all_answered:
|
| 290 |
st.session_state["current_page"] += 1
|
| 291 |
st.rerun()
|
|
|
|
| 296 |
st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
|
| 297 |
|
| 298 |
|
| 299 |
+
elif st.session_state["current_page"] == 2: # Last Page
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
st.markdown('<p class="big-font">Thank you for participating! <br> Click on the button below to submit your answers. </p>', unsafe_allow_html=True)
|
| 301 |
st.button('Submit Responses', disabled = st.session_state["disabled"], on_click = button_disable)
|
| 302 |
if st.session_state["disabled"]:
|
|
|
|
| 306 |
"Q1": Q1_radio_options[st.session_state["Q1"]],
|
| 307 |
"Q2": st.session_state["Q2"],
|
| 308 |
"Q3": Q3_radio_options[st.session_state["Q3"]],
|
| 309 |
+
"Q4": Q4_radio_options[st.session_state["Q4"]],
|
| 310 |
+
"Q5": Q5_radio_options[st.session_state["Q5"]],
|
| 311 |
+
"Q6": Q6_radio_options[st.session_state["Q6"]],
|
| 312 |
}
|
| 313 |
submission(response)
|
| 314 |
except Exception as e:
|
| 315 |
print(e)
|
| 316 |
st.error(f'An error ocurred. Here is the error message: {e}', icon="🚨")
|
| 317 |
|
| 318 |
+
print("Success!")
|
| 319 |
|
| 320 |
if st.button('Back'):
|
| 321 |
st.session_state["current_page"] -= 1
|