anastaa3 commited on
Commit
12fbc41
·
verified ·
1 Parent(s): 6874d15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -272
app.py CHANGED
@@ -3,14 +3,12 @@ import requests
3
  import json
4
  import web3
5
 
6
- total_number_pages = 8
7
  placeholder_buttons = None
8
 
9
- Q3_radio_options = ["Option 1 multi","Option 2 multi"]
10
- Q4_radio_options = ["Option 1 Radio","Option 2 Radio"]
11
- Q5_radio_options = ["Green","Red","Blue","Yellow"]
12
- Q6_radio_options = ["Yes","No","Ur dumb"]
13
- Q10_radio_options = ["IDK","Of Course","STFU!!!!!","Inner demons"]
14
 
15
 
16
  # Function that records radio element changes
@@ -30,7 +28,7 @@ def answer_change(state, key):
30
  st.session_state[state] = st.session_state[key]
31
 
32
  st.set_page_config(page_title='IPFS-Based Survey',)
33
- st.title('Newest Test')
34
 
35
  st.markdown("<style>.row-widget.stButton {text-align: center;}</style>", unsafe_allow_html=True)
36
  st.markdown("<style>.big-font {font-size:24px;}</style>", unsafe_allow_html=True)
@@ -41,312 +39,78 @@ if "current_page" not in st.session_state:
41
  st.session_state["Q1"] = None
42
  st.session_state["Q2"] = None
43
  st.session_state["Q3"] = None
44
- st.session_state["Q4"] = None
45
- st.session_state["Q5"] = None
46
- st.session_state["Q6"] = None
47
- st.session_state["Q7"] = None
48
- st.session_state["Q8"] = None
49
- st.session_state["Q9"] = None
50
- st.session_state["Q10"] = None
51
  st.session_state["disabled"] = False
52
 
53
  # Page 1; Video
54
  if st.session_state["current_page"] == 1:
55
 
56
- st.markdown("""<p class="big-font">This is a Test of the latest version of the survey builder Tool</p>""", unsafe_allow_html=True)
57
 
58
- st.video("https://www.youtube.com/watch?v=aJb6Dov0jlM")
59
- st.text_area(label = "This is a text Question and should allow any text input. This should appear on the first page.",
60
- value= "" if st.session_state["Q1"] == None else st.session_state["Q1"],
61
- key = 'Q1_text',
62
- on_change = answer_change,
63
- args = ( "Q1", "Q1_text",))
64
-
65
- st.markdown("""<style> div[class*="stText"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
66
-
67
-
68
- placeholder = st.empty()
69
-
70
- if st.button('Next', key='next_button_page_1'):
71
- all_answered = True
72
- if st.session_state["Q1"] == None or st.session_state["Q1"] == []:
73
- all_answered = False
74
- if all_answered:
75
- st.session_state["current_page"] += 1
76
- st.rerun()
77
- else:
78
- with placeholder.container():
79
- st.warning("Please answer all the questions on this page.", icon="⚠️")
80
-
81
- st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
82
-
83
-
84
- elif st.session_state["current_page"] == 2:
85
-
86
- if st.session_state["Q2"] == None:
87
- st.session_state["Q2"] = 5
88
- 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,
89
- value= st.session_state["Q2"],
90
- key = "Q2_slider",
91
- on_change = answer_change,
92
- args = ("Q2", "Q2_slider",))
93
- st.markdown("""<style> div[class*="stSlider"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
94
-
95
-
96
- st.multiselect(label = "This is a multiselect question where you can select multiple answers. This should appear on the second page.",
97
- default = None if st.session_state["Q3"] == None else st.session_state["Q3"],
98
- options = Q3_radio_options,
99
- key = 'Q3_multi',
100
- on_change = multi_change,
101
- args = (Q3_radio_options, "Q3", "Q3_multi",))
102
-
103
- st.markdown("""<style> div[class*="stMulti"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
104
-
105
-
106
- placeholder = st.empty()
107
-
108
- col1, col2 = st.columns(2)
109
- with col1:
110
- if st.button('Back'):
111
- st.session_state["current_page"] -= 1
112
- st.rerun()
113
- with col2:
114
- if st.button('Next'):
115
- all_answered = True
116
- if st.session_state["Q2"] == None or st.session_state["Q2"] == []:
117
- all_answered = False
118
- if st.session_state["Q3"] == None or st.session_state["Q3"] == []:
119
- all_answered = False
120
- if all_answered:
121
- st.session_state["current_page"] += 1
122
- st.rerun()
123
- else:
124
- with placeholder.container():
125
- st.warning("Please answer all the questions on this page.", icon="⚠️")
126
-
127
- st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
128
-
129
-
130
- elif st.session_state["current_page"] == 3:
131
-
132
- st.radio(label = "This is a multiple choice question where you can choose one of the following. This should appear on the third page.",
133
- options = Q4_radio_options,
134
- index = None if st.session_state["Q4"] == None else st.session_state["Q4"],
135
- key = 'Q4_radio',
136
  on_change = radio_change,
137
- args = (Q4_radio_options, "Q4", "Q4_radio",))
138
 
139
  st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
140
 
141
 
142
- st.radio(label = "Fav Color?",
143
- options = Q5_radio_options,
144
- index = None if st.session_state["Q5"] == None else st.session_state["Q5"],
145
- key = 'Q5_radio',
146
  on_change = radio_change,
147
- args = (Q5_radio_options, "Q5", "Q5_radio",))
148
 
149
  st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
150
 
151
 
152
- st.multiselect(label = "Party Time",
153
- default = None if st.session_state["Q6"] == None else st.session_state["Q6"],
154
- options = Q6_radio_options,
155
- key = 'Q6_multi',
156
- on_change = multi_change,
157
- args = (Q6_radio_options, "Q6", "Q6_multi",))
158
-
159
- st.markdown("""<style> div[class*="stMulti"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
160
-
161
-
162
- placeholder = st.empty()
163
-
164
- col1, col2 = st.columns(2)
165
- with col1:
166
- if st.button('Back'):
167
- st.session_state["current_page"] -= 1
168
- st.rerun()
169
- with col2:
170
- if st.button('Next'):
171
- all_answered = True
172
- if st.session_state["Q4"] == None or st.session_state["Q4"] == []:
173
- all_answered = False
174
- if st.session_state["Q5"] == None or st.session_state["Q5"] == []:
175
- all_answered = False
176
- if st.session_state["Q6"] == None or st.session_state["Q6"] == []:
177
- all_answered = False
178
- if all_answered:
179
- st.session_state["current_page"] += 1
180
- st.rerun()
181
- else:
182
- with placeholder.container():
183
- st.warning("Please answer all the questions on this page.", icon="⚠️")
184
-
185
- st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
186
-
187
-
188
- elif st.session_state["current_page"] == 4:
189
-
190
- if st.session_state["Q7"] == None:
191
- st.session_state["Q7"] = 50
192
- st.slider(label="Happiness Scale",min_value=0,max_value=100,
193
- value= st.session_state["Q7"],
194
- key = "Q7_slider",
195
- on_change = answer_change,
196
- args = ("Q7", "Q7_slider",))
197
- st.markdown("""<style> div[class*="stSlider"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
198
-
199
-
200
- st.text_area(label = "Why are you this happy/unhappy?",
201
- value= "" if st.session_state["Q8"] == None else st.session_state["Q8"],
202
- key = 'Q8_text',
203
- on_change = answer_change,
204
- args = ( "Q8", "Q8_text",))
205
-
206
- st.markdown("""<style> div[class*="stText"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
207
-
208
-
209
- placeholder = st.empty()
210
-
211
- col1, col2 = st.columns(2)
212
- with col1:
213
- if st.button('Back'):
214
- st.session_state["current_page"] -= 1
215
- st.rerun()
216
- with col2:
217
- if st.button('Next'):
218
- all_answered = True
219
- if st.session_state["Q7"] == None or st.session_state["Q7"] == []:
220
- all_answered = False
221
- if st.session_state["Q8"] == None or st.session_state["Q8"] == []:
222
- all_answered = False
223
- if all_answered:
224
- st.session_state["current_page"] += 1
225
- st.rerun()
226
- else:
227
- with placeholder.container():
228
- st.warning("Please answer all the questions on this page.", icon="⚠️")
229
-
230
- st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
231
-
232
-
233
- elif st.session_state["current_page"] == 5:
234
-
235
- placeholder = st.empty()
236
-
237
- col1, col2 = st.columns(2)
238
- with col1:
239
- if st.button('Back'):
240
- st.session_state["current_page"] -= 1
241
- st.rerun()
242
- with col2:
243
- if st.button('Next'):
244
- all_answered = True
245
- if all_answered:
246
- st.session_state["current_page"] += 1
247
- st.rerun()
248
- else:
249
- with placeholder.container():
250
- st.warning("Please answer all the questions on this page.", icon="⚠️")
251
-
252
- st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
253
-
254
-
255
- elif st.session_state["current_page"] == 6:
256
-
257
- st.select_slider(label = "This is the best survey builder in the world",
258
- options = ["N/A", "Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"],
259
- value= None if st.session_state["Q9"] == None else st.session_state["Q9"],
260
- key = 'Q9_select_slider',
261
- on_change = answer_change,
262
- args = ("Q9", "Q9_select_slider",))
263
-
264
- st.markdown("""<style> div[class*="stSelectSlider"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
265
-
266
-
267
- st.radio(label = "I like cheese?",
268
- options = Q10_radio_options,
269
- index = None if st.session_state["Q10"] == None else st.session_state["Q10"],
270
- key = 'Q10_radio',
271
  on_change = radio_change,
272
- args = (Q10_radio_options, "Q10", "Q10_radio",))
273
 
274
  st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
275
 
276
 
277
  placeholder = st.empty()
278
 
279
- col1, col2 = st.columns(2)
280
- with col1:
281
- if st.button('Back'):
282
- st.session_state["current_page"] -= 1
283
- st.rerun()
284
- with col2:
285
- if st.button('Next'):
286
- all_answered = True
287
- if st.session_state["Q9"] == None or st.session_state["Q9"] == []:
288
- all_answered = False
289
- if st.session_state["Q10"] == None or st.session_state["Q10"] == []:
290
- all_answered = False
291
- if all_answered:
292
- st.session_state["current_page"] += 1
293
- st.rerun()
294
- else:
295
- with placeholder.container():
296
- st.warning("Please answer all the questions on this page.", icon="⚠️")
297
-
298
- st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
299
-
300
-
301
- elif st.session_state["current_page"] == 7:
302
-
303
- placeholder = st.empty()
304
-
305
- col1, col2 = st.columns(2)
306
- with col1:
307
- if st.button('Back'):
308
- st.session_state["current_page"] -= 1
309
  st.rerun()
310
- with col2:
311
- if st.button('Next'):
312
- all_answered = True
313
- if all_answered:
314
- st.session_state["current_page"] += 1
315
- st.rerun()
316
- else:
317
- with placeholder.container():
318
- st.warning("Please answer all the questions on this page.", icon="⚠️")
319
 
320
  st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
321
 
322
 
323
- elif st.session_state["current_page"] == 8: # Last Page
324
  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)
325
  st.button('Submit Responses', disabled = st.session_state["disabled"], on_click = button_disable)
326
  if st.session_state["disabled"]:
327
  with st.spinner(r"$\textsf{\normalsize Storing data on IPFS and Ethereum. This operation might take a few minutes. Please wait to receive your confirmation code!}$"):
328
  try:
329
  response = {'file': json.dumps({
330
- "Q1": st.session_state["Q1"],
331
  "Q2": st.session_state["Q2"],
332
  "Q3": st.session_state["Q3"],
333
- "Q4": Q4_radio_options[st.session_state["Q4"]],
334
- "Q5": Q5_radio_options[st.session_state["Q5"]],
335
- "Q6": st.session_state["Q6"],
336
- "Q7": st.session_state["Q7"],
337
- "Q8": st.session_state["Q8"],
338
- "Q9": st.session_state["Q9"],
339
- "Q10": Q10_radio_options[st.session_state["Q10"]],
340
  })}
341
- with open("results.txt", "w") as file:
342
- file.write(response['file'])
343
-
344
  except Exception as e:
345
  print(e)
346
  st.error(f'An error ocurred. Here is the error message: {e}', icon="🚨")
347
 
348
-
349
-
350
  if st.button('Back'):
351
  st.session_state["current_page"] -= 1
352
  st.rerun()
 
3
  import json
4
  import web3
5
 
6
+ total_number_pages = 2
7
  placeholder_buttons = None
8
 
9
+ Q1_radio_options = ["radio option 1","radio option 2","radio option 3","IDK"]
10
+ Q2_radio_options = ["N/A", "Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"]
11
+ Q3_radio_options = ["N/A", "Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"]
 
 
12
 
13
 
14
  # Function that records radio element changes
 
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
  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,
51
+ index = None if st.session_state["Q1"] == None else st.session_state["Q1"],
52
+ key = 'Q1_radio',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  on_change = radio_change,
54
+ args = (Q1_radio_options, "Q1", "Q1_radio",))
55
 
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.radio(label = "This survey is amazing", # Likert
60
+ options = Q2_radio_options,
61
+ index = None if st.session_state["Q2"] == None else st.session_state["Q2"],
62
+ key = 'Q2_radio',
63
  on_change = radio_change,
64
+ args = (Q2_radio_options, "Q2", "Q2_radio",))
65
 
66
  st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 18px;}</style> <br><br>""", unsafe_allow_html=True)
67
 
68
 
69
+ st.radio(label = "I smell", # Likert
70
+ options = Q3_radio_options,
71
+ index = None if st.session_state["Q3"] == None else st.session_state["Q3"],
72
+ key = 'Q3_radio',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  on_change = radio_change,
74
+ args = (Q3_radio_options, "Q3", "Q3_radio",))
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
+ if st.button('Next'):
82
+ all_answered = True
83
+ if st.session_state["Q1"] == None or st.session_state["Q1"] == []:
84
+ all_answered = False
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
+ 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: # Last 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"]:
103
  with st.spinner(r"$\textsf{\normalsize Storing data on IPFS and Ethereum. This operation might take a few minutes. Please wait to receive your confirmation code!}$"):
104
  try:
105
  response = {'file': json.dumps({
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)
112
  st.error(f'An error ocurred. Here is the error message: {e}', icon="🚨")
113
 
 
 
114
  if st.button('Back'):
115
  st.session_state["current_page"] -= 1
116
  st.rerun()