parass13 commited on
Commit
63b376d
Β·
verified Β·
1 Parent(s): 6262fed

Update dashboard.py

Browse files
Files changed (1) hide show
  1. dashboard.py +3 -29
dashboard.py CHANGED
@@ -93,28 +93,6 @@ def login_user(email, password):
93
  return bcrypt.checkpw(password.encode(), stored_hash.encode())
94
  return False
95
 
96
- def get_user_stats():
97
- url = f"{SUPABASE_URL}/rest/v1/{SUPABASE_TABLE}?select=gender"
98
- r = requests.get(url, headers=headers)
99
- if r.status_code != 200:
100
- return "Failed to fetch user stats."
101
-
102
- users = r.json()
103
- total = len(users)
104
- gender_counts = {"Male": 0, "Female": 0, "Other": 0}
105
- for u in users:
106
- g = u.get("gender", "Other")
107
- gender_counts[g] = gender_counts.get(g, 0) + 1
108
-
109
- stats = f"""
110
- ### πŸ“Š Dashboard
111
- - πŸ‘₯ Total Users: **{total}**
112
- - 🚹 Male: **{gender_counts['Male']}**
113
- - 🚺 Female: **{gender_counts['Female']}**
114
- - 🌈 Other: **{gender_counts['Other']}**
115
- """
116
- return stats
117
-
118
  # --- UI ---
119
  with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as demo:
120
  is_logged_in = gr.State(False)
@@ -136,7 +114,6 @@ with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as
136
  email_login = gr.Textbox(label="Email")
137
  password_login = gr.Textbox(label="Password", type="password")
138
  login_btn = gr.Button("Login", variant="primary")
139
- dashboard_stats = gr.Markdown(visible=False)
140
  with gr.Accordion("New User? Click here to Sign Up", open=False) as signup_accordion:
141
  name_signup = gr.Textbox(label="Name")
142
  phone_signup = gr.Textbox(label="Phone (10 digits)")
@@ -161,21 +138,18 @@ with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as
161
 
162
  def update_ui_on_auth_change(logged_in_status):
163
  if logged_in_status:
164
- stats = get_user_stats()
165
  return (
166
  gr.update(visible=False),
167
  gr.update(visible=True),
168
  gr.update(selected=DETECT_TAB_NAME),
169
- gr.update(value="βœ… Login successful!", visible=True),
170
- gr.update(value=stats, visible=True)
171
  )
172
  else:
173
  return (
174
  gr.update(visible=True),
175
  gr.update(visible=False),
176
  gr.update(selected=LOGIN_TAB_NAME),
177
- gr.update(value="", visible=False),
178
- gr.update(visible=False)
179
  )
180
 
181
  def handle_login(email, password):
@@ -196,7 +170,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as
196
 
197
  login_btn.click(fn=handle_login, inputs=[email_login, password_login], outputs=[is_logged_in, message_output])
198
  logout_btn.click(fn=handle_logout, inputs=[], outputs=[is_logged_in, email_login, password_login])
199
- is_logged_in.change(fn=update_ui_on_auth_change, inputs=is_logged_in, outputs=[login_tab, detect_tab, tabs, message_output, dashboard_stats])
200
  signup_btn.click(
201
  fn=handle_signup,
202
  inputs=[name_signup, phone_signup, email_signup, gender_signup, password_signup],
 
93
  return bcrypt.checkpw(password.encode(), stored_hash.encode())
94
  return False
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  # --- UI ---
97
  with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as demo:
98
  is_logged_in = gr.State(False)
 
114
  email_login = gr.Textbox(label="Email")
115
  password_login = gr.Textbox(label="Password", type="password")
116
  login_btn = gr.Button("Login", variant="primary")
 
117
  with gr.Accordion("New User? Click here to Sign Up", open=False) as signup_accordion:
118
  name_signup = gr.Textbox(label="Name")
119
  phone_signup = gr.Textbox(label="Phone (10 digits)")
 
138
 
139
  def update_ui_on_auth_change(logged_in_status):
140
  if logged_in_status:
 
141
  return (
142
  gr.update(visible=False),
143
  gr.update(visible=True),
144
  gr.update(selected=DETECT_TAB_NAME),
145
+ gr.update(value="βœ… Login successful!", visible=True)
 
146
  )
147
  else:
148
  return (
149
  gr.update(visible=True),
150
  gr.update(visible=False),
151
  gr.update(selected=LOGIN_TAB_NAME),
152
+ gr.update(value="", visible=False)
 
153
  )
154
 
155
  def handle_login(email, password):
 
170
 
171
  login_btn.click(fn=handle_login, inputs=[email_login, password_login], outputs=[is_logged_in, message_output])
172
  logout_btn.click(fn=handle_logout, inputs=[], outputs=[is_logged_in, email_login, password_login])
173
+ is_logged_in.change(fn=update_ui_on_auth_change, inputs=is_logged_in, outputs=[login_tab, detect_tab, tabs, message_output])
174
  signup_btn.click(
175
  fn=handle_signup,
176
  inputs=[name_signup, phone_signup, email_signup, gender_signup, password_signup],