Spaces:
Sleeping
Sleeping
first save
Browse files- __pycache__/form_helper.cpython-313.pyc +0 -0
- app.py +10 -0
- form_helper.py +87 -0
- requirements.txt +1 -0
__pycache__/form_helper.cpython-313.pyc
ADDED
Binary file (6.67 kB). View file
|
|
app.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from form_helper import FormHelper
|
3 |
+
|
4 |
+
def main():
|
5 |
+
form_helper = FormHelper()
|
6 |
+
form_helper.run()
|
7 |
+
|
8 |
+
|
9 |
+
if __name__ == "__main__":
|
10 |
+
main()
|
form_helper.py
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
class FormHelper:
|
4 |
+
def __init__(self):
|
5 |
+
"""Initializes the FormHelper with default session state values."""
|
6 |
+
if "exam_loaded" not in st.session_state:
|
7 |
+
st.session_state.exam_loaded = False
|
8 |
+
if "exam_started" not in st.session_state:
|
9 |
+
st.session_state.exam_started = False
|
10 |
+
if "current_form" not in st.session_state:
|
11 |
+
st.session_state.current_form = "about"
|
12 |
+
|
13 |
+
def show_about_page(self):
|
14 |
+
"""Displays the About page."""
|
15 |
+
st.title("About This App")
|
16 |
+
st.write("This is a dummy app for demonstrating form management in Streamlit.")
|
17 |
+
|
18 |
+
def show_load_exam_page(self):
|
19 |
+
"""Displays the Load Exam page and handles exam loading."""
|
20 |
+
st.title("Load Exam")
|
21 |
+
st.write("Simulating exam loading...")
|
22 |
+
if st.button("Exam Loaded"):
|
23 |
+
st.session_state.exam_loaded = True
|
24 |
+
st.session_state.current_form = "take_exam"
|
25 |
+
st.rerun()
|
26 |
+
|
27 |
+
def show_take_exam_page(self):
|
28 |
+
"""Displays the Take Exam page with dummy questions and handles exam finishing."""
|
29 |
+
st.title("Take Exam")
|
30 |
+
st.session_state.exam_started = True
|
31 |
+
st.write("Displaying exam questions here...")
|
32 |
+
for i in range(5):
|
33 |
+
st.write(f"Question {i+1}: What is the capital of France?")
|
34 |
+
st.radio(f"Select answer for question {i+1}", ("Berlin", "Paris", "Madrid", "Rome"))
|
35 |
+
if st.button("Finish Exam"):
|
36 |
+
st.session_state.exam_started = False
|
37 |
+
st.session_state.current_form = "view_result"
|
38 |
+
st.rerun()
|
39 |
+
if st.button("End Exam Early"):
|
40 |
+
st.session_state.exam_started = False
|
41 |
+
st.session_state.current_form = "view_result"
|
42 |
+
st.rerun()
|
43 |
+
|
44 |
+
def show_view_result_page(self):
|
45 |
+
"""Displays the View Result page with dummy results and handles exam retake/reload."""
|
46 |
+
st.title("View Result")
|
47 |
+
st.write("Displaying exam results here...")
|
48 |
+
st.write("You answered 3 out of 5 questions correctly.")
|
49 |
+
if st.button("Retake Exam"):
|
50 |
+
st.session_state.current_form = "take_exam"
|
51 |
+
st.rerun()
|
52 |
+
if st.button("Load Another Exam"):
|
53 |
+
st.session_state.exam_loaded = False
|
54 |
+
st.session_state.current_form = "load_exam"
|
55 |
+
st.rerun()
|
56 |
+
|
57 |
+
def show_sidebar(self):
|
58 |
+
"""Displays the sidebar with navigation buttons."""
|
59 |
+
with st.sidebar:
|
60 |
+
st.title("Navigation")
|
61 |
+
if st.button("About"):
|
62 |
+
st.session_state.current_form = "about"
|
63 |
+
st.rerun()
|
64 |
+
if not st.session_state.exam_started:
|
65 |
+
if st.button("Load Exam"):
|
66 |
+
st.session_state.current_form = "load_exam"
|
67 |
+
st.rerun()
|
68 |
+
if st.session_state.exam_loaded and st.session_state.exam_started:
|
69 |
+
if st.button("Take Exam"):
|
70 |
+
st.session_state.current_form = "take_exam"
|
71 |
+
st.rerun()
|
72 |
+
if "current_form" in st.session_state and st.session_state.current_form == "view_result":
|
73 |
+
if st.button("View Result"):
|
74 |
+
st.session_state.current_form = "view_result"
|
75 |
+
st.rerun()
|
76 |
+
|
77 |
+
def run(self):
|
78 |
+
"""Runs the app by displaying the appropriate page based on the current form."""
|
79 |
+
self.show_sidebar()
|
80 |
+
if st.session_state.current_form == "about":
|
81 |
+
self.show_about_page()
|
82 |
+
elif st.session_state.current_form == "load_exam":
|
83 |
+
self.show_load_exam_page()
|
84 |
+
elif st.session_state.current_form == "take_exam":
|
85 |
+
self.show_take_exam_page()
|
86 |
+
elif st.session_state.current_form == "view_result":
|
87 |
+
self.show_view_result_page()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
streamlit
|