Spaces:
Sleeping
Sleeping
Update dashboard.py
Browse files- dashboard.py +24 -13
dashboard.py
CHANGED
@@ -90,8 +90,11 @@ def login_user(email, password):
|
|
90 |
url = f"{SUPABASE_URL}/rest/v1/{SUPABASE_TABLE}?email=eq.{email}"
|
91 |
r = requests.get(url, headers=headers)
|
92 |
if r.status_code == 200 and r.json():
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
95 |
return False
|
96 |
|
97 |
# --- UI ---
|
@@ -105,8 +108,9 @@ GUIDE_TAB_NAME = "π User Guide"
|
|
105 |
with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as demo:
|
106 |
is_logged_in = gr.State(False)
|
107 |
|
108 |
-
|
109 |
-
|
|
|
110 |
with gr.Row():
|
111 |
with gr.Column():
|
112 |
gr.Markdown("""
|
@@ -118,7 +122,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as
|
|
118 |
</div>
|
119 |
""", elem_id="home-markdown")
|
120 |
|
121 |
-
with gr.Tab(LOGIN_TAB_NAME,
|
122 |
with gr.Row():
|
123 |
with gr.Column(scale=1):
|
124 |
gr.Markdown("## Welcome!", "Login to access the detector, or sign up for a new account.")
|
@@ -136,7 +140,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as
|
|
136 |
password_signup = gr.Textbox(label="Create Password", type="password")
|
137 |
signup_btn = gr.Button("Sign Up")
|
138 |
|
139 |
-
with gr.Tab(DETECT_TAB_NAME, visible=False) as detect_tab:
|
140 |
with gr.Row():
|
141 |
gr.Markdown("## Deepfake Detector")
|
142 |
logout_btn = gr.Button("Logout")
|
@@ -146,9 +150,9 @@ with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as
|
|
146 |
result = gr.Textbox(label="Prediction Result", interactive=False)
|
147 |
predict_btn = gr.Button("Predict", variant="primary")
|
148 |
|
149 |
-
with gr.Tab(ABOUT_TAB_NAME): about.layout()
|
150 |
-
with gr.Tab(COMMUNITY_TAB_NAME): community.layout()
|
151 |
-
with gr.Tab(GUIDE_TAB_NAME): user_guide.layout()
|
152 |
|
153 |
gr.HTML("""
|
154 |
<style>
|
@@ -162,20 +166,25 @@ with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as
|
|
162 |
</style>
|
163 |
""")
|
164 |
|
|
|
165 |
def update_ui_on_auth_change(logged_in_status):
|
166 |
if logged_in_status:
|
|
|
167 |
return (
|
168 |
gr.update(visible=False), # login_tab
|
169 |
gr.update(visible=True), # detect_tab
|
170 |
gr.update(visible=False), # home_tab
|
171 |
-
gr.update(value="β
Login successful!", visible=True)
|
|
|
172 |
)
|
173 |
else:
|
|
|
174 |
return (
|
175 |
gr.update(visible=True), # login_tab
|
176 |
gr.update(visible=False), # detect_tab
|
177 |
gr.update(visible=True), # home_tab
|
178 |
-
gr.update(value="", visible=False)
|
|
|
179 |
)
|
180 |
|
181 |
def handle_login(email, password):
|
@@ -196,10 +205,12 @@ 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(
|
200 |
fn=update_ui_on_auth_change,
|
201 |
inputs=is_logged_in,
|
202 |
-
outputs=[login_tab, detect_tab, home_tab, message_output]
|
203 |
)
|
204 |
signup_btn.click(fn=handle_signup, inputs=[name_signup, phone_signup, email_signup, gender_signup, password_signup],
|
205 |
outputs=[message_output, name_signup, phone_signup, email_signup, gender_signup, password_signup, signup_accordion])
|
@@ -208,4 +219,4 @@ with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as
|
|
208 |
demo.load(lambda: False, None, [is_logged_in])
|
209 |
|
210 |
if __name__ == "__main__":
|
211 |
-
demo.launch()
|
|
|
90 |
url = f"{SUPABASE_URL}/rest/v1/{SUPABASE_TABLE}?email=eq.{email}"
|
91 |
r = requests.get(url, headers=headers)
|
92 |
if r.status_code == 200 and r.json():
|
93 |
+
try:
|
94 |
+
stored_hash = r.json()[0]["password"]
|
95 |
+
return bcrypt.checkpw(password.encode('utf-8'), stored_hash.encode('utf-8'))
|
96 |
+
except (IndexError, KeyError):
|
97 |
+
return False
|
98 |
return False
|
99 |
|
100 |
# --- UI ---
|
|
|
108 |
with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as demo:
|
109 |
is_logged_in = gr.State(False)
|
110 |
|
111 |
+
# --- FIX 1: Set a default selected tab ---
|
112 |
+
with gr.Tabs(selected=HOME_TAB_NAME) as tabs:
|
113 |
+
with gr.Tab(HOME_TAB_NAME, id=HOME_TAB_NAME) as home_tab:
|
114 |
with gr.Row():
|
115 |
with gr.Column():
|
116 |
gr.Markdown("""
|
|
|
122 |
</div>
|
123 |
""", elem_id="home-markdown")
|
124 |
|
125 |
+
with gr.Tab(LOGIN_TAB_NAME, id=LOGIN_TAB_NAME) as login_tab:
|
126 |
with gr.Row():
|
127 |
with gr.Column(scale=1):
|
128 |
gr.Markdown("## Welcome!", "Login to access the detector, or sign up for a new account.")
|
|
|
140 |
password_signup = gr.Textbox(label="Create Password", type="password")
|
141 |
signup_btn = gr.Button("Sign Up")
|
142 |
|
143 |
+
with gr.Tab(DETECT_TAB_NAME, id=DETECT_TAB_NAME, visible=False) as detect_tab:
|
144 |
with gr.Row():
|
145 |
gr.Markdown("## Deepfake Detector")
|
146 |
logout_btn = gr.Button("Logout")
|
|
|
150 |
result = gr.Textbox(label="Prediction Result", interactive=False)
|
151 |
predict_btn = gr.Button("Predict", variant="primary")
|
152 |
|
153 |
+
with gr.Tab(ABOUT_TAB_NAME, id=ABOUT_TAB_NAME): about.layout()
|
154 |
+
with gr.Tab(COMMUNITY_TAB_NAME, id=COMMUNITY_TAB_NAME): community.layout()
|
155 |
+
with gr.Tab(GUIDE_TAB_NAME, id=GUIDE_TAB_NAME): user_guide.layout()
|
156 |
|
157 |
gr.HTML("""
|
158 |
<style>
|
|
|
166 |
</style>
|
167 |
""")
|
168 |
|
169 |
+
# --- FIX 2: Modify the function to also control which tab is selected ---
|
170 |
def update_ui_on_auth_change(logged_in_status):
|
171 |
if logged_in_status:
|
172 |
+
# On successful login, hide login/home, show detector, and select the detector tab
|
173 |
return (
|
174 |
gr.update(visible=False), # login_tab
|
175 |
gr.update(visible=True), # detect_tab
|
176 |
gr.update(visible=False), # home_tab
|
177 |
+
gr.update(value="β
Login successful!", visible=True),
|
178 |
+
gr.update(selected=DETECT_TAB_NAME) # This selects the tab
|
179 |
)
|
180 |
else:
|
181 |
+
# On logout or initial load, show login/home, hide detector, and select the home tab
|
182 |
return (
|
183 |
gr.update(visible=True), # login_tab
|
184 |
gr.update(visible=False), # detect_tab
|
185 |
gr.update(visible=True), # home_tab
|
186 |
+
gr.update(value="", visible=False),
|
187 |
+
gr.update(selected=HOME_TAB_NAME) # This selects the tab
|
188 |
)
|
189 |
|
190 |
def handle_login(email, password):
|
|
|
205 |
|
206 |
login_btn.click(fn=handle_login, inputs=[email_login, password_login], outputs=[is_logged_in, message_output])
|
207 |
logout_btn.click(fn=handle_logout, inputs=[], outputs=[is_logged_in, email_login, password_login])
|
208 |
+
|
209 |
+
# --- FIX 3: Add the `tabs` component to the outputs of the change event ---
|
210 |
is_logged_in.change(
|
211 |
fn=update_ui_on_auth_change,
|
212 |
inputs=is_logged_in,
|
213 |
+
outputs=[login_tab, detect_tab, home_tab, message_output, tabs]
|
214 |
)
|
215 |
signup_btn.click(fn=handle_signup, inputs=[name_signup, phone_signup, email_signup, gender_signup, password_signup],
|
216 |
outputs=[message_output, name_signup, phone_signup, email_signup, gender_signup, password_signup, signup_accordion])
|
|
|
219 |
demo.load(lambda: False, None, [is_logged_in])
|
220 |
|
221 |
if __name__ == "__main__":
|
222 |
+
demo.launch()
|