Spaces:
Sleeping
Sleeping
File size: 4,797 Bytes
8831520 f84e1e9 8831520 f84e1e9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | 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) |