parass13 commited on
Commit
1e390f9
Β·
verified Β·
1 Parent(s): 5506ce9

Update dashboard.py

Browse files
Files changed (1) hide show
  1. dashboard.py +40 -40
dashboard.py CHANGED
@@ -7,14 +7,21 @@ from PIL import Image
7
  import tensorflow as tf
8
  import os
9
  import warnings
10
-
 
11
 
12
  from pages import about, community, user_guide
13
 
14
- # --- Supabase Config ---
15
  SUPABASE_URL = "https://fpbuhzbdtzwomjwytqul.supabase.co"
16
- SUPABASE_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZwYnVoemJkdHp3b21qd3l0cXVsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTE5NDk3NzYsImV4cCI6MjA2NzUyNTc3Nn0.oAa2TNNPQMyOGk63AOMZ7XKcwYvy5m-xoSWyvMZd6FY"
17
- supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
 
 
 
 
 
 
18
 
19
  # --- Setup ---
20
  os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
@@ -62,37 +69,29 @@ def register_user(name, phone, email, gender, password):
62
  if not is_valid_email(email): return "❌ Invalid email format."
63
  if not is_valid_phone(phone): return "❌ Phone must be 10 digits."
64
 
65
- try:
66
- existing = supabase.table("user_details").select("email").eq("email", email).execute()
67
- if existing.data:
68
- return "⚠️ Email already registered."
69
-
70
- hashed_pw = bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt()).decode("utf-8")
71
-
72
- supabase.table("user_details").insert({
73
- "name": name,
74
- "phone": phone,
75
- "email": email,
76
- "gender": gender,
77
- "password": hashed_pw
78
- }).execute()
79
-
80
- return "βœ… Registration successful! Please log in."
81
-
82
- except Exception as e:
83
- print(f"Supabase error: {e}")
84
- return "❌ A Supabase error occurred."
85
 
86
  def login_user(email, password):
87
- if not email or not password: return False
88
- try:
89
- result = supabase.table("user_details").select("password").eq("email", email).execute()
90
- if result.data and bcrypt.checkpw(password.encode('utf-8'), result.data[0]["password"].encode("utf-8")):
91
- return True
92
- return False
93
- except Exception as e:
94
- print(f"Supabase login error: {e}")
95
- return False
96
 
97
  # --- UI ---
98
  with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as demo:
@@ -108,12 +107,12 @@ with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as
108
  with gr.Tab(LOGIN_TAB_NAME) as login_tab:
109
  with gr.Row():
110
  with gr.Column(scale=1):
111
- gr.Markdown("## Welcome to VerifiAI!", "Login to access the detector, or sign up for a new account.")
112
  with gr.Column(scale=2):
113
  gr.Markdown("### Login or Sign Up")
114
  message_output = gr.Markdown(visible=False)
115
- email_login = gr.Textbox(label="Email", elem_id="login_email")
116
- password_login = gr.Textbox(label="Password", type="password", elem_id="login_pass")
117
  login_btn = gr.Button("Login", variant="primary")
118
  with gr.Accordion("New User? Click here to Sign Up", open=False) as signup_accordion:
119
  name_signup = gr.Textbox(label="Name")
@@ -137,8 +136,6 @@ with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as
137
  with gr.Tab(COMMUNITY_TAB_NAME): community.layout()
138
  with gr.Tab(GUIDE_TAB_NAME): user_guide.layout()
139
 
140
- # --- Events ---
141
-
142
  def update_ui_on_auth_change(logged_in_status):
143
  if logged_in_status:
144
  return (
@@ -174,8 +171,11 @@ with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as
174
  login_btn.click(fn=handle_login, inputs=[email_login, password_login], outputs=[is_logged_in, message_output])
175
  logout_btn.click(fn=handle_logout, inputs=[], outputs=[is_logged_in, email_login, password_login])
176
  is_logged_in.change(fn=update_ui_on_auth_change, inputs=is_logged_in, outputs=[login_tab, detect_tab, tabs, message_output])
177
- signup_btn.click(fn=handle_signup, inputs=[name_signup, phone_signup, email_signup, gender_signup, password_signup],
178
- outputs=[message_output, name_signup, phone_signup, email_signup, gender_signup, password_signup, signup_accordion])
 
 
 
179
  predict_btn.click(fn=predict_image, inputs=image_input, outputs=result)
180
 
181
  if __name__ == "__main__":
 
7
  import tensorflow as tf
8
  import os
9
  import warnings
10
+ import requests
11
+ import json
12
 
13
  from pages import about, community, user_guide
14
 
15
+ # --- Config ---
16
  SUPABASE_URL = "https://fpbuhzbdtzwomjwytqul.supabase.co"
17
+ SUPABASE_API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZwYnVoemJkdHp3b21qd3l0cXVsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTE5NDk3NzYsImV4cCI6MjA2NzUyNTc3Nn0.oAa2TNNPQMyOGk63AOMZ7XKcwYvy5m-xoSWyvMZd6FY"
18
+ SUPABASE_TABLE = "user_details"
19
+
20
+ headers = {
21
+ "apikey": SUPABASE_API_KEY,
22
+ "Authorization": f"Bearer {SUPABASE_API_KEY}",
23
+ "Content-Type": "application/json"
24
+ }
25
 
26
  # --- Setup ---
27
  os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
 
69
  if not is_valid_email(email): return "❌ Invalid email format."
70
  if not is_valid_phone(phone): return "❌ Phone must be 10 digits."
71
 
72
+ query_url = f"{SUPABASE_URL}/rest/v1/{SUPABASE_TABLE}?email=eq.{email}"
73
+ r = requests.get(query_url, headers=headers)
74
+ if r.status_code == 200 and len(r.json()) > 0:
75
+ return "⚠️ Email already registered."
76
+
77
+ hashed_pw = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode()
78
+ data = {
79
+ "name": name,
80
+ "phone": phone,
81
+ "email": email,
82
+ "gender": gender,
83
+ "password": hashed_pw
84
+ }
85
+ r = requests.post(f"{SUPABASE_URL}/rest/v1/{SUPABASE_TABLE}", headers=headers, data=json.dumps(data))
86
+ return "βœ… Registration successful! Please log in." if r.status_code == 201 else "❌ Error during registration."
 
 
 
 
 
87
 
88
  def login_user(email, password):
89
+ url = f"{SUPABASE_URL}/rest/v1/{SUPABASE_TABLE}?email=eq.{email}"
90
+ r = requests.get(url, headers=headers)
91
+ if r.status_code == 200 and r.json():
92
+ stored_hash = r.json()[0]["password"]
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:
 
107
  with gr.Tab(LOGIN_TAB_NAME) as login_tab:
108
  with gr.Row():
109
  with gr.Column(scale=1):
110
+ gr.Markdown("## Welcome!", "Login to access the detector, or sign up for a new account.")
111
  with gr.Column(scale=2):
112
  gr.Markdown("### Login or Sign Up")
113
  message_output = gr.Markdown(visible=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")
 
136
  with gr.Tab(COMMUNITY_TAB_NAME): community.layout()
137
  with gr.Tab(GUIDE_TAB_NAME): user_guide.layout()
138
 
 
 
139
  def update_ui_on_auth_change(logged_in_status):
140
  if logged_in_status:
141
  return (
 
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],
177
+ outputs=[message_output, name_signup, phone_signup, email_signup, gender_signup, password_signup, signup_accordion]
178
+ )
179
  predict_btn.click(fn=predict_image, inputs=image_input, outputs=result)
180
 
181
  if __name__ == "__main__":