Spaces:
Build error
Build error
Max-Dupler
commited on
Commit
·
df914dc
1
Parent(s):
693ede2
adding generated survey
Browse files
app.py
CHANGED
|
@@ -1,74 +1,57 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import json
|
| 3 |
import requests
|
|
|
|
| 4 |
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
def store_in_ipfs(data):
|
| 7 |
-
url = 'https://ipfs.infura.io:5001/api/v0/add'
|
| 8 |
-
# Convert the data dictionary to JSON format
|
| 9 |
-
files = {'file': json.dumps(data)}
|
| 10 |
-
# Send POST request to IPFS using Infura endpoint
|
| 11 |
-
response = requests.post(
|
| 12 |
-
url,
|
| 13 |
-
files=files,
|
| 14 |
-
auth=(st.secrets["username"], st.secrets["password"])
|
| 15 |
-
)
|
| 16 |
-
# Check for successful response
|
| 17 |
-
if response.status_code == 200:
|
| 18 |
-
return response.json()['Hash'] # Return IPFS hash of the stored data
|
| 19 |
-
else:
|
| 20 |
-
raise Exception(f"Failed to store in IPFS: {response.text}")
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def main():
|
| 24 |
-
st.title("Basic Survey")
|
| 25 |
-
|
| 26 |
-
# Introductory text
|
| 27 |
-
st.write("Welcome to our basic survey! Please fill out the information below.")
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
# Name input
|
| 31 |
-
name = st.text_input("What's your name?")
|
| 32 |
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
|
|
|
| 44 |
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
st.success(f"Thank you {name} for your submission!")
|
| 49 |
-
st.write(f"Name: {name}")
|
| 50 |
-
st.write(f"Age: {age}")
|
| 51 |
-
st.write(f"Gender: {gender}")
|
| 52 |
-
st.write(f"Feedback: {feedback}")
|
| 53 |
|
|
|
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
| 72 |
|
|
|
|
| 73 |
|
| 74 |
|
|
|
|
| 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)
|
| 22 |
|
| 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)
|
| 37 |
+
with col1:
|
| 38 |
+
if st.button('Back'):
|
| 39 |
+
st.session_state["current_page"] -= 1
|
| 40 |
+
st.rerun()
|
| 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
|
| 50 |
+
st.rerun()
|
| 51 |
+
else:
|
| 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 |
|