Max-Dupler commited on
Commit
a9f0da4
·
1 Parent(s): df914dc

updating survey, the survey generation is working in the web app

Browse files
Files changed (1) hide show
  1. app.py +69 -9
app.py CHANGED
@@ -1,21 +1,32 @@
1
  import streamlit as st
2
  import requests
3
  import json
 
4
 
5
- total_number_pages = 1
6
  placeholder_buttons = None
7
 
 
8
 
9
 
10
  # Function that records radio element changes
11
  def radio_change(element, state, key):
12
  st.session_state[state] = element.index(st.session_state[key]) # Setting previously selected option
 
 
 
 
 
 
13
  # Function that disables the last button while data is uploaded to IPFS
14
  def button_disable():
15
  st.session_state['disabled'] = True
16
 
 
 
 
17
  st.set_page_config(page_title='IPFS-Based Survey',)
18
- st.title('Test Survey')
19
 
20
  st.markdown("<style>.row-widget.stButton {text-align: center;}</style>", unsafe_allow_html=True)
21
  st.markdown("<style>.big-font {font-size:24px;}</style>", unsafe_allow_html=True)
@@ -23,14 +34,67 @@ st.markdown("<style>.big-font {font-size:24px;}</style>", unsafe_allow_html=True
23
 
24
  if "current_page" not in st.session_state:
25
  st.session_state["current_page"] = 1
 
 
 
26
  st.session_state["disabled"] = False
27
 
28
  # Page 1; Video
29
  if st.session_state["current_page"] == 1:
30
 
31
- st.markdown("""<p class="big-font">My Test</p>""", unsafe_allow_html=True)
32
  st.video("https://www.youtube.com/watch?v=aJb6Dov0jlM")
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  placeholder = st.empty()
35
 
36
  col1, col2 = st.columns(2)
@@ -41,9 +105,7 @@ if st.session_state["current_page"] == 1:
41
  with col2:
42
  if st.button('Next'):
43
  all_answered = True
44
- if st.session_state["Q1"] == None:
45
- all_answered = False
46
- if st.session_state["Q2"] == None:
47
  all_answered = False
48
  if all_answered:
49
  st.session_state["current_page"] += 1
@@ -52,6 +114,4 @@ if st.session_state["current_page"] == 1:
52
  with placeholder.container():
53
  st.warning("Please answer all the questions on this page.", icon="⚠️")
54
 
55
- st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
56
-
57
-
 
1
  import streamlit as st
2
  import requests
3
  import json
4
+ # import web3
5
 
6
+ total_number_pages = 2
7
  placeholder_buttons = None
8
 
9
+ Q3_radio_options = ["Fresh","Soph","Jr","Sr","N/A"]
10
 
11
 
12
  # Function that records radio element changes
13
  def radio_change(element, state, key):
14
  st.session_state[state] = element.index(st.session_state[key]) # Setting previously selected option
15
+
16
+ def multi_change(element, state, key):
17
+ st.session_state[state] = []
18
+ for selected_option in st.session_state[key]:
19
+ st.session_state[state].append(selected_option)
20
+
21
  # Function that disables the last button while data is uploaded to IPFS
22
  def button_disable():
23
  st.session_state['disabled'] = True
24
 
25
+ def answer_change(state, key):
26
+ st.session_state[state] = st.session_state[key]
27
+
28
  st.set_page_config(page_title='IPFS-Based Survey',)
29
+ st.title('test survey')
30
 
31
  st.markdown("<style>.row-widget.stButton {text-align: center;}</style>", unsafe_allow_html=True)
32
  st.markdown("<style>.big-font {font-size:24px;}</style>", unsafe_allow_html=True)
 
34
 
35
  if "current_page" not in st.session_state:
36
  st.session_state["current_page"] = 1
37
+ st.session_state["Q1"] = None
38
+ st.session_state["Q2"] = None
39
+ st.session_state["Q3"] = None
40
  st.session_state["disabled"] = False
41
 
42
  # Page 1; Video
43
  if st.session_state["current_page"] == 1:
44
 
45
+ st.markdown("""<p class="big-font">this is a test</p>""", unsafe_allow_html=True)
46
  st.video("https://www.youtube.com/watch?v=aJb6Dov0jlM")
47
 
48
+ st.text_area(label = "whats your favorite color",
49
+ value= "" if st.session_state["Q1"] == None else st.session_state["Q1"],
50
+ key = 'Q1_text',
51
+ on_change = answer_change,
52
+ args = ( "Q1", "Q1_text",))
53
+
54
+ # The code below changes the font size of the above radio's label.
55
+ st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True)
56
+
57
+
58
+ st.slider(label="how confident are you in your ability to skate",min_value=0,max_value=10,
59
+ value= 5 if st.session_state["Q2"] == None else st.session_state["Q2"],
60
+ key = "Q2_slider",
61
+ on_change = answer_change,
62
+ args = ("Q2", "Q2_slider",))
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
+ if st.button('Next', key='next_button_page_1'):
70
+ all_answered = True
71
+ if st.session_state["Q1"] == None:
72
+ all_answered = False
73
+ if st.session_state["Q2"] == None:
74
+ all_answered = False
75
+ if all_answered:
76
+ st.session_state["current_page"] += 1
77
+ st.rerun()
78
+ else:
79
+ with placeholder.container():
80
+ st.warning("Please answer all the questions on this page.", icon="⚠️")
81
+
82
+ st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")
83
+
84
+
85
+ elif st.session_state["current_page"] == 2:
86
+
87
+ st.radio(label = "what year are you in college",
88
+ options = Q3_radio_options,
89
+ index = None if st.session_state["Q3"] == None else st.session_state["Q3"],
90
+ key = 'Q3_radio',
91
+ on_change = radio_change,
92
+ args = (Q3_radio_options, "Q3", "Q3_radio",))
93
+
94
+ # The code below changes the font size of the above radio's label.
95
+ st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True)
96
+
97
+
98
  placeholder = st.empty()
99
 
100
  col1, col2 = st.columns(2)
 
105
  with col2:
106
  if st.button('Next'):
107
  all_answered = True
108
+ if st.session_state["Q3"] == None:
 
 
109
  all_answered = False
110
  if all_answered:
111
  st.session_state["current_page"] += 1
 
114
  with placeholder.container():
115
  st.warning("Please answer all the questions on this page.", icon="⚠️")
116
 
117
+ st.progress(st.session_state["current_page"]/total_number_pages, text="Progress")