Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,12 +3,13 @@ import requests
|
|
| 3 |
import json
|
| 4 |
import web3
|
| 5 |
|
| 6 |
-
total_number_pages =
|
| 7 |
placeholder_buttons = None
|
| 8 |
|
| 9 |
-
Q1_radio_options = ["radio option 1","radio option 2","radio option 3","
|
| 10 |
-
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
# Function that records radio element changes
|
|
@@ -28,7 +29,7 @@ def answer_change(state, key):
|
|
| 28 |
st.session_state[state] = st.session_state[key]
|
| 29 |
|
| 30 |
st.set_page_config(page_title='IPFS-Based Survey',)
|
| 31 |
-
st.title('')
|
| 32 |
|
| 33 |
st.markdown("<style>.row-widget.stButton {text-align: center;}</style>", unsafe_allow_html=True)
|
| 34 |
st.markdown("<style>.big-font {font-size:24px;}</style>", unsafe_allow_html=True)
|
|
@@ -39,12 +40,15 @@ if "current_page" not in st.session_state:
|
|
| 39 |
st.session_state["Q1"] = None
|
| 40 |
st.session_state["Q2"] = None
|
| 41 |
st.session_state["Q3"] = None
|
|
|
|
|
|
|
|
|
|
| 42 |
st.session_state["disabled"] = False
|
| 43 |
|
| 44 |
# Page 1; Video
|
| 45 |
if st.session_state["current_page"] == 1:
|
| 46 |
|
| 47 |
-
st.markdown("""<p class="big-font"></p>""", unsafe_allow_html=True)
|
| 48 |
|
| 49 |
st.radio(label = "This is the radio question",
|
| 50 |
options = Q1_radio_options,
|
|
@@ -56,47 +60,131 @@ if st.session_state["current_page"] == 1:
|
|
| 56 |
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 57 |
|
| 58 |
|
| 59 |
-
st.
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
args = (Q2_radio_options, "Q2", "Q2_radio",))
|
| 65 |
|
| 66 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
-
st.
|
|
|
|
| 70 |
options = Q3_radio_options,
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
on_change = radio_change,
|
| 74 |
-
args = (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 77 |
|
| 78 |
|
| 79 |
placeholder = st.empty()
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
if st.
|
| 84 |
-
|
| 85 |
-
if st.session_state["Q2"] == None or st.session_state["Q2"] == []:
|
| 86 |
-
all_answered = False
|
| 87 |
-
if st.session_state["Q3"] == None or st.session_state["Q3"] == []:
|
| 88 |
-
all_answered = False
|
| 89 |
-
if all_answered:
|
| 90 |
-
st.session_state["current_page"] += 1
|
| 91 |
st.rerun()
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
|
| 97 |
|
| 98 |
|
| 99 |
-
elif st.session_state["current_page"] ==
|
| 100 |
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)
|
| 101 |
st.button('Submit Responses', disabled = st.session_state["disabled"], on_click = button_disable)
|
| 102 |
if st.session_state["disabled"]:
|
|
@@ -106,6 +194,9 @@ elif st.session_state["current_page"] == 2: # Last Page
|
|
| 106 |
"Q1": Q1_radio_options[st.session_state["Q1"]],
|
| 107 |
"Q2": st.session_state["Q2"],
|
| 108 |
"Q3": st.session_state["Q3"],
|
|
|
|
|
|
|
|
|
|
| 109 |
})}
|
| 110 |
except Exception as e:
|
| 111 |
print(e)
|
|
|
|
| 3 |
import json
|
| 4 |
import web3
|
| 5 |
|
| 6 |
+
total_number_pages = 4
|
| 7 |
placeholder_buttons = None
|
| 8 |
|
| 9 |
+
Q1_radio_options = ["radio option 1","radio option 2","radio option 3","Option 4?"]
|
| 10 |
+
Q3_radio_options = ["Wowzers","This is super crazy","Not very crazy","midly crazy"]
|
| 11 |
+
Q4_radio_options = ["Def not crazy","Crazy","Pizza","What am I doing?"]
|
| 12 |
+
Q6_radio_options = ["N/A", "Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"]
|
| 13 |
|
| 14 |
|
| 15 |
# Function that records radio element changes
|
|
|
|
| 29 |
st.session_state[state] = st.session_state[key]
|
| 30 |
|
| 31 |
st.set_page_config(page_title='IPFS-Based Survey',)
|
| 32 |
+
st.title('Test Survey')
|
| 33 |
|
| 34 |
st.markdown("<style>.row-widget.stButton {text-align: center;}</style>", unsafe_allow_html=True)
|
| 35 |
st.markdown("<style>.big-font {font-size:24px;}</style>", unsafe_allow_html=True)
|
|
|
|
| 40 |
st.session_state["Q1"] = None
|
| 41 |
st.session_state["Q2"] = None
|
| 42 |
st.session_state["Q3"] = None
|
| 43 |
+
st.session_state["Q4"] = None
|
| 44 |
+
st.session_state["Q5"] = None
|
| 45 |
+
st.session_state["Q6"] = None
|
| 46 |
st.session_state["disabled"] = False
|
| 47 |
|
| 48 |
# Page 1; Video
|
| 49 |
if st.session_state["current_page"] == 1:
|
| 50 |
|
| 51 |
+
st.markdown("""<p class="big-font">This is a test survey</p>""", unsafe_allow_html=True)
|
| 52 |
|
| 53 |
st.radio(label = "This is the radio question",
|
| 54 |
options = Q1_radio_options,
|
|
|
|
| 60 |
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 61 |
|
| 62 |
|
| 63 |
+
st.video("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
|
| 64 |
+
st.markdown("""<p style='font-size:18px;'>Rick rolled</p>""", unsafe_allow_html=True)
|
| 65 |
+
st.image("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSU_fgVbH_LfgbKK6qvziW5SgG7vxdoNMI-atQ3T7fYpX14W3u9ib3G1aMFB-9Se-INjq9RRPjpADux5kP09LaWcA")
|
| 66 |
+
st.markdown("""<p style='font-size:18px;'>Elephant</p>""", unsafe_allow_html=True)
|
| 67 |
+
placeholder = st.empty()
|
|
|
|
| 68 |
|
| 69 |
+
if st.button('Next', key='next_button_page_1'):
|
| 70 |
+
all_answered = True
|
| 71 |
+
if st.session_state["Q1"] == None or st.session_state["Q1"] == []:
|
| 72 |
+
all_answered = False
|
| 73 |
+
if all_answered:
|
| 74 |
+
st.session_state["current_page"] += 1
|
| 75 |
+
st.rerun()
|
| 76 |
+
else:
|
| 77 |
+
with placeholder.container():
|
| 78 |
+
st.warning("Please answer all the questions on this page.", icon="⚠️")
|
| 79 |
+
|
| 80 |
+
st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
elif st.session_state["current_page"] == 2:
|
| 84 |
+
|
| 85 |
+
st.text_area(label = "This is a text input question!",
|
| 86 |
+
value= "" if st.session_state["Q2"] == None else st.session_state["Q2"],
|
| 87 |
+
key = 'Q2_text',
|
| 88 |
+
on_change = answer_change,
|
| 89 |
+
args = ( "Q2", "Q2_text",))
|
| 90 |
+
|
| 91 |
+
st.markdown("""<style> div[class*="stText"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 92 |
|
| 93 |
|
| 94 |
+
st.multiselect(label = "Multiple Selection question!!!!????!?!?!",
|
| 95 |
+
default = None if st.session_state["Q3"] == None else st.session_state["Q3"],
|
| 96 |
options = Q3_radio_options,
|
| 97 |
+
key = 'Q3_multi',
|
| 98 |
+
on_change = multi_change,
|
| 99 |
+
args = (Q3_radio_options, "Q3", "Q3_multi",))
|
| 100 |
+
|
| 101 |
+
st.markdown("""<style> div[class*="stMulti"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
st.selectbox(label = "Single selection question. ",
|
| 105 |
+
options = Q4_radio_options,
|
| 106 |
+
index = None if st.session_state["Q4"] == None else st.session_state["Q4"],
|
| 107 |
+
key = 'Q4_radio',
|
| 108 |
on_change = radio_change,
|
| 109 |
+
args = (Q4_radio_options, "Q4", "Q4_radio",))
|
| 110 |
+
|
| 111 |
+
st.markdown("""<style> div[class*="stSelectbox"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
if st.session_state["Q5"] == None:
|
| 115 |
+
st.session_state["Q5"] = 525
|
| 116 |
+
st.slider(label="Slider question to choose a number between 50 and 1000",min_value=50,max_value=1000,
|
| 117 |
+
value= st.session_state["Q5"],
|
| 118 |
+
key = "Q5_slider",
|
| 119 |
+
on_change = answer_change,
|
| 120 |
+
args = ("Q5", "Q5_slider",))
|
| 121 |
+
st.markdown("""<style> div[class*="stSlider"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
st.radio(label = "Likert. This was a good survey", # Likert
|
| 125 |
+
options = Q6_radio_options,
|
| 126 |
+
index = None if st.session_state["Q6"] == None else st.session_state["Q6"],
|
| 127 |
+
key = 'Q6_radio',
|
| 128 |
+
on_change = radio_change,
|
| 129 |
+
args = (Q6_radio_options, "Q6", "Q6_radio",))
|
| 130 |
|
| 131 |
st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
|
| 132 |
|
| 133 |
|
| 134 |
placeholder = st.empty()
|
| 135 |
|
| 136 |
+
col1, col2 = st.columns(2)
|
| 137 |
+
with col1:
|
| 138 |
+
if st.button('Back'):
|
| 139 |
+
st.session_state["current_page"] -= 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
st.rerun()
|
| 141 |
+
with col2:
|
| 142 |
+
if st.button('Next'):
|
| 143 |
+
all_answered = True
|
| 144 |
+
if st.session_state["Q2"] == None or st.session_state["Q2"] == []:
|
| 145 |
+
all_answered = False
|
| 146 |
+
if st.session_state["Q3"] == None or st.session_state["Q3"] == []:
|
| 147 |
+
all_answered = False
|
| 148 |
+
if st.session_state["Q4"] == None or st.session_state["Q4"] == []:
|
| 149 |
+
all_answered = False
|
| 150 |
+
if st.session_state["Q5"] == None or st.session_state["Q5"] == []:
|
| 151 |
+
all_answered = False
|
| 152 |
+
if st.session_state["Q6"] == None or st.session_state["Q6"] == []:
|
| 153 |
+
all_answered = False
|
| 154 |
+
if all_answered:
|
| 155 |
+
st.session_state["current_page"] += 1
|
| 156 |
+
st.rerun()
|
| 157 |
+
else:
|
| 158 |
+
with placeholder.container():
|
| 159 |
+
st.warning("Please answer all the questions on this page.", icon="⚠️")
|
| 160 |
+
|
| 161 |
+
st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
elif st.session_state["current_page"] == 3:
|
| 165 |
+
|
| 166 |
+
st.markdown("""<p style='font-size:18px;'>Yay a nice blank page</p>""", unsafe_allow_html=True)
|
| 167 |
+
placeholder = st.empty()
|
| 168 |
+
|
| 169 |
+
col1, col2 = st.columns(2)
|
| 170 |
+
with col1:
|
| 171 |
+
if st.button('Back'):
|
| 172 |
+
st.session_state["current_page"] -= 1
|
| 173 |
+
st.rerun()
|
| 174 |
+
with col2:
|
| 175 |
+
if st.button('Next'):
|
| 176 |
+
all_answered = True
|
| 177 |
+
if all_answered:
|
| 178 |
+
st.session_state["current_page"] += 1
|
| 179 |
+
st.rerun()
|
| 180 |
+
else:
|
| 181 |
+
with placeholder.container():
|
| 182 |
+
st.warning("Please answer all the questions on this page.", icon="⚠️")
|
| 183 |
|
| 184 |
st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
|
| 185 |
|
| 186 |
|
| 187 |
+
elif st.session_state["current_page"] == 4: # Last Page
|
| 188 |
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)
|
| 189 |
st.button('Submit Responses', disabled = st.session_state["disabled"], on_click = button_disable)
|
| 190 |
if st.session_state["disabled"]:
|
|
|
|
| 194 |
"Q1": Q1_radio_options[st.session_state["Q1"]],
|
| 195 |
"Q2": st.session_state["Q2"],
|
| 196 |
"Q3": st.session_state["Q3"],
|
| 197 |
+
"Q4": st.session_state["Q4"],
|
| 198 |
+
"Q5": st.session_state["Q5"],
|
| 199 |
+
"Q6": st.session_state["Q6"],
|
| 200 |
})}
|
| 201 |
except Exception as e:
|
| 202 |
print(e)
|