Spaces:
Build error
Build error
| import streamlit as st | |
| import requests | |
| import json | |
| # import web3 | |
| total_number_pages = 2 | |
| placeholder_buttons = None | |
| Q3_radio_options = ["Fresh","Soph","Jr","Sr","N/A"] | |
| # Function that records radio element changes | |
| def radio_change(element, state, key): | |
| st.session_state[state] = element.index(st.session_state[key]) # Setting previously selected option | |
| def multi_change(element, state, key): | |
| st.session_state[state] = [] | |
| for selected_option in st.session_state[key]: | |
| st.session_state[state].append(selected_option) | |
| # Function that disables the last button while data is uploaded to IPFS | |
| def button_disable(): | |
| st.session_state['disabled'] = True | |
| def answer_change(state, key): | |
| st.session_state[state] = st.session_state[key] | |
| st.set_page_config(page_title='IPFS-Based Survey',) | |
| st.title('test survey') | |
| st.markdown("<style>.row-widget.stButton {text-align: center;}</style>", unsafe_allow_html=True) | |
| st.markdown("<style>.big-font {font-size:24px;}</style>", unsafe_allow_html=True) | |
| if "current_page" not in st.session_state: | |
| st.session_state["current_page"] = 1 | |
| st.session_state["Q1"] = None | |
| st.session_state["Q2"] = None | |
| st.session_state["Q3"] = None | |
| st.session_state["disabled"] = False | |
| # Page 1; Video | |
| if st.session_state["current_page"] == 1: | |
| st.markdown("""<p class="big-font">this is a test</p>""", unsafe_allow_html=True) | |
| st.video("https://www.youtube.com/watch?v=aJb6Dov0jlM") | |
| st.text_area(label = "whats your favorite color", | |
| value= "" if st.session_state["Q1"] == None else st.session_state["Q1"], | |
| key = 'Q1_text', | |
| on_change = answer_change, | |
| args = ( "Q1", "Q1_text",)) | |
| # The code below changes the font size of the above radio's label. | |
| st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True) | |
| st.slider(label="how confident are you in your ability to skate",min_value=0,max_value=10, | |
| value= 5 if st.session_state["Q2"] == None else st.session_state["Q2"], | |
| key = "Q2_slider", | |
| on_change = answer_change, | |
| args = ("Q2", "Q2_slider",)) | |
| # The code below changes the font size of the above radio's label. | |
| st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True) | |
| placeholder = st.empty() | |
| if st.button('Next', key='next_button_page_1'): | |
| all_answered = True | |
| if st.session_state["Q1"] == None: | |
| all_answered = False | |
| if st.session_state["Q2"] == None: | |
| all_answered = False | |
| if all_answered: | |
| st.session_state["current_page"] += 1 | |
| st.rerun() | |
| else: | |
| with placeholder.container(): | |
| st.warning("Please answer all the questions on this page.", icon="⚠️") | |
| st.progress(st.session_state["current_page"]/total_number_pages, text="Progress") | |
| elif st.session_state["current_page"] == 2: | |
| st.radio(label = "what year are you in college", | |
| options = Q3_radio_options, | |
| index = None if st.session_state["Q3"] == None else st.session_state["Q3"], | |
| key = 'Q3_radio', | |
| on_change = radio_change, | |
| args = (Q3_radio_options, "Q3", "Q3_radio",)) | |
| # The code below changes the font size of the above radio's label. | |
| st.markdown("""<style> div[class*="stRadio"] > label > div[data-testid="stMarkdownContainer"] > p {font-size: 24px;}</style> <br><br>""", unsafe_allow_html=True) | |
| placeholder = st.empty() | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| if st.button('Back'): | |
| st.session_state["current_page"] -= 1 | |
| st.rerun() | |
| with col2: | |
| if st.button('Next'): | |
| all_answered = True | |
| if st.session_state["Q3"] == None: | |
| all_answered = False | |
| if all_answered: | |
| st.session_state["current_page"] += 1 | |
| st.rerun() | |
| else: | |
| with placeholder.container(): | |
| st.warning("Please answer all the questions on this page.", icon="⚠️") | |
| st.progress(st.session_state["current_page"]/total_number_pages, text="Progress") |