-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
128 lines (100 loc) · 3.63 KB
/
app.py
File metadata and controls
128 lines (100 loc) · 3.63 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
import streamlit as st
from sklearn.linear_model import LogisticRegression
from database import (
init_db,
register_user_db,
authenticate_user_db
)
# 🔥 MUST BE FIRST STREAMLIT COMMAND
st.set_page_config(page_title="Artha AI", layout="wide")
# -------- Background --------
from styles.login_bg import load_login_background
# ---------------- DATABASE INIT ----------------
init_db() # ✅ This now creates both users & transactions tables
# ---------------- SESSION INIT ----------------
if "authenticated" not in st.session_state:
st.session_state.authenticated = False
if "username" not in st.session_state:
st.session_state.username = None
if "last_risk" not in st.session_state:
st.session_state.last_risk = None
if "page" not in st.session_state:
st.session_state.page = "login"
# ================= LOGIN PAGE =================
if st.session_state.page == "login":
st.markdown(load_login_background(), unsafe_allow_html=True)
st.markdown("""
<style>
.brand-box {
width: 50%;
margin: 60px auto 25px auto;
padding: 22px;
background: #0f1419;
border-radius: 16px;
text-align: center;
}
.brand-title {
font-size: 36px;
font-weight: 600;
letter-spacing: 1px;
color: #e6f1f2;
font-family: 'Segoe UI', sans-serif;
}
.brand-title span {
color: #00c2b8;
font-weight: 700;
}
</style>
<div class="brand-box">
<div class="brand-title">
Artha <span>AI</span>
</div>
</div>
""", unsafe_allow_html=True)
col1, col2, col3 = st.columns([1, 2, 1])
with col2:
st.markdown(
"<h3 style='text-align:center;'>Fintech Risk Intelligence Platform</h3>",
unsafe_allow_html=True
)
tab1, tab2 = st.tabs(["Login", "Sign Up"])
# ---------- LOGIN ----------
with tab1:
username = st.text_input("Username", key="login_user")
password = st.text_input("Password", type="password", key="login_pass")
if st.button("Login"):
if authenticate_user_db(username, password):
st.session_state.authenticated = True
st.session_state.username = username.lower().strip() # ✅ lowercase fix
st.session_state.page = "dashboard"
st.rerun()
else:
st.error("Invalid credentials")
# ---------- SIGN UP ----------
with tab2:
new_user = st.text_input("New Username", key="signup_user")
new_pass = st.text_input("New Password", type="password", key="signup_pass")
if st.button("Register"):
if register_user_db(new_user, new_pass):
st.success("User registered successfully. Please login.")
else:
st.error("Username already exists.")
# ================= DASHBOARD =================
elif st.session_state.page == "dashboard":
st.title("🚀 Artha AI - Fintech Risk & Payment Intelligence Platform")
st.sidebar.success(f"Logged in as {st.session_state.username}")
if st.sidebar.button("Logout"):
st.session_state.clear() # ✅ clean logout
st.rerun()
st.divider()
col1, col2, col3 = st.columns(3)
col1.metric("User", st.session_state.username)
col2.metric("Authentication", "Active")
col3.metric(
"Last Risk Score",
st.session_state.last_risk
if st.session_state.last_risk is not None
else "N/A"
)
st.divider()
st.info("Use the sidebar to navigate between modules.")