Spaces:
Sleeping
Sleeping
Download src/streamlit_app.py from jayanth-2005/1: direct link, hf CLI and curl.
- Browser
- Download file 4.8 kB
-
https://huggingface.co/spaces/jayanth-2005/1/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/jayanth-2005/1/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/jayanth-2005/1/resolve/main/src/streamlit_app.py
4.8 kB
| import streamlit as st | |
| from utils.auth import login_user, signup_user, init_db | |
| # Initialize the database | |
| init_db() | |
| st.set_page_config(page_title="๐ธ BharatPlay", layout="wide") | |
| # Session management | |
| if "authenticated" not in st.session_state: | |
| st.session_state.authenticated = False | |
| if "username" not in st.session_state: | |
| st.session_state.username = None | |
| # Header | |
| st.markdown("<h1 style='text-align:center;color:#6A1B9A;'>๐ธ BharatPlay</h1>", unsafe_allow_html=True) | |
| st.markdown("<h3 style='text-align:center;'>Explore & Contribute to Indian Games</h3>", unsafe_allow_html=True) | |
| st.markdown("---") | |
| # Login/signup form | |
| if not st.session_state.authenticated: | |
| tab1, tab2 = st.tabs(["๐ Login", "๐ Sign Up"]) | |
| with tab1: | |
| with st.form("login_form"): | |
| username = st.text_input("Username") | |
| password = st.text_input("Password", type="password") | |
| if st.form_submit_button("Login"): | |
| if login_user(username, password): | |
| st.session_state.authenticated = True | |
| st.session_state.username = username | |
| st.success(f"โ Welcome, {username}!") | |
| st.rerun() | |
| else: | |
| st.error("โ Invalid credentials.") | |
| with tab2: | |
| with st.form("signup_form"): | |
| new_user = st.text_input("Choose Username") | |
| new_pass = st.text_input("Choose Password", type="password") | |
| if st.form_submit_button("Sign Up"): | |
| if new_user and new_pass: | |
| if signup_user(new_user, new_pass): | |
| st.success("๐ Account created! Please log in.") | |
| else: | |
| st.error("โ ๏ธ Username already exists.") | |
| else: | |
| st.warning("Please fill both fields.") | |
| st.stop() | |
| if not st.session_state.authenticated: | |
| tab1, tab2 = st.tabs(["๐ Login", "๐ Sign Up"]) | |
| with tab1: | |
| with st.form("login_form"): | |
| username = st.text_input("Username") | |
| password = st.text_input("Password", type="password") | |
| if st.form_submit_button("Login"): | |
| if login_user(username, password): | |
| st.session_state.authenticated = True | |
| st.session_state.username = username | |
| st.success(f"โ Welcome, {username}!") | |
| st.rerun() | |
| else: | |
| st.error("โ Invalid credentials.") | |
| with tab2: | |
| with st.form("signup_form"): | |
| new_user = st.text_input("Choose Username") | |
| new_pass = st.text_input("Choose Password", type="password") | |
| if st.form_submit_button("Sign Up"): | |
| if new_user and new_pass: | |
| if signup_user(new_user, new_pass): | |
| st.success("๐ Account created! Please log in.") | |
| else: | |
| st.error("โ ๏ธ Username already exists.") | |
| else: | |
| st.warning("Please fill both fields.") | |
| st.stop() | |
| # Add in your app.py, after login section | |
| with st.sidebar: | |
| if st.session_state.authenticated: | |
| st.markdown("### ๐ง Account") | |
| st.success(f"โ Logged in as `{st.session_state.username}`") | |
| if st.button("๐ช Logout"): | |
| st.session_state.authenticated = False | |
| st.session_state.username = None | |
| st.rerun() | |
| st.markdown("### ๐ฎ Choose a Game Category:") | |
| categories = [ | |
| {"name": "Indoor", "icon": "๐ฒ", "desc": "Games played indoors.", "page": "1_Indoor"}, | |
| {"name": "Outdoor", "icon": "๐", "desc": "Games played outdoors.", "page": "2_Outdoor"}, | |
| {"name": "Traditional", "icon": "๐ช", "desc": "Culturally rooted Indian games.", "page": "3_Traditional"}, | |
| {"name": "Martial Arts", "icon": "๐ฅ", "desc": "Combat-based sports.", "page": "4_Martial_Arts"}, | |
| {"name": "Upload History", "icon": "๐", "desc": "View all uploads.", "page": "5_Upload_history"}, | |
| ] | |
| cols = st.columns(2) | |
| for i, cat in enumerate(categories): | |
| with cols[i % 2]: | |
| with st.container(): | |
| st.markdown(f""" | |
| <div style='background-color:#f3e5f5;padding:20px;border-radius:15px; | |
| box-shadow:0 0 10px #bbb;margin-bottom:10px;'> | |
| <h3 style='color:#4A148C;margin-bottom:10px;'>{cat['icon']} {cat['name']}</h3> | |
| <p style='margin-bottom:20px;'>{cat['desc']}</p> | |
| """, unsafe_allow_html=True) | |
| # ๐ข Button placed inside the card | |
| st.page_link(f"pages/{cat['page']}.py", label=f"โก๏ธ Explore {cat['name']}", use_container_width=True) | |
| st.markdown("</div>", unsafe_allow_html=True) |