Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,40 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
2 |
import home
|
3 |
import prediction
|
4 |
import about
|
5 |
import contact
|
6 |
|
7 |
-
# β
|
8 |
-
st.set_page_config(page_title="TransPolymer", layout="wide", page_icon="π§ͺ")
|
9 |
-
|
10 |
-
# β
Page router using a dictionary
|
11 |
-
PAGES = {
|
12 |
-
"Home": home,
|
13 |
-
"Predictions": prediction,
|
14 |
-
"About": about,
|
15 |
-
"Contact": contact
|
16 |
-
}
|
17 |
-
|
18 |
-
# β
Sidebar Navigation
|
19 |
st.sidebar.title("π Navigation")
|
20 |
-
page = st.sidebar.radio("Select a Page",
|
21 |
|
22 |
-
# β
URL
|
23 |
query_params = st.query_params
|
24 |
if "page" in query_params:
|
25 |
param_page = query_params["page"][0].capitalize()
|
26 |
-
if param_page in
|
27 |
page = param_page
|
28 |
|
29 |
-
# β
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
|
33 |
|
|
|
1 |
import streamlit as st
|
2 |
+
|
3 |
+
# β
This MUST be first!
|
4 |
+
st.set_page_config(page_title="TransPolymer", layout="wide", page_icon="π§ͺ")
|
5 |
+
|
6 |
+
# β
Then import your modules
|
7 |
import home
|
8 |
import prediction
|
9 |
import about
|
10 |
import contact
|
11 |
|
12 |
+
# β
Navigation Sidebar
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
st.sidebar.title("π Navigation")
|
14 |
+
page = st.sidebar.radio("Select a Page", ["Home", "Predictions", "About", "Contact"])
|
15 |
|
16 |
+
# β
Optional: Override from URL like ?page=Contact
|
17 |
query_params = st.query_params
|
18 |
if "page" in query_params:
|
19 |
param_page = query_params["page"][0].capitalize()
|
20 |
+
if param_page in ["Home", "Predictions", "About", "Contact"]:
|
21 |
page = param_page
|
22 |
|
23 |
+
# β
Page rendering logic
|
24 |
+
def load_page(page_name):
|
25 |
+
if page_name == "Home":
|
26 |
+
home.show()
|
27 |
+
elif page_name == "Predictions":
|
28 |
+
prediction.show()
|
29 |
+
elif page_name == "About":
|
30 |
+
about.show()
|
31 |
+
elif page_name == "Contact":
|
32 |
+
contact.show()
|
33 |
+
else:
|
34 |
+
st.error("Page not found.")
|
35 |
+
|
36 |
+
load_page(page)
|
37 |
+
|
38 |
|
39 |
|
40 |
|