Spaces:
Running
Running
Update dashboard.py
Browse files- dashboard.py +18 -22
dashboard.py
CHANGED
@@ -102,10 +102,9 @@ ABOUT_TAB_NAME = "βΉοΈ About"
|
|
102 |
COMMUNITY_TAB_NAME = "π Community"
|
103 |
GUIDE_TAB_NAME = "π User Guide"
|
104 |
|
105 |
-
# ... [imports and other code remain unchanged above]
|
106 |
-
|
107 |
with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as demo:
|
108 |
is_logged_in = gr.State(False)
|
|
|
109 |
|
110 |
with gr.Tabs() as tabs:
|
111 |
with gr.Tab(HOME_TAB_NAME, visible=True) as home_tab:
|
@@ -167,29 +166,29 @@ with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as
|
|
167 |
def update_ui_on_auth_change(logged_in_status):
|
168 |
if logged_in_status:
|
169 |
return (
|
170 |
-
gr.update(visible=False),
|
171 |
-
gr.update(visible=True),
|
172 |
-
gr.update(visible=False),
|
173 |
gr.update(value="β
Login successful!", visible=True),
|
174 |
-
|
175 |
)
|
176 |
else:
|
177 |
return (
|
178 |
-
gr.update(visible=True),
|
179 |
-
gr.update(visible=False),
|
180 |
-
gr.update(visible=True),
|
181 |
gr.update(value="", visible=False),
|
182 |
-
|
183 |
)
|
184 |
|
185 |
def handle_login(email, password):
|
186 |
if login_user(email, password):
|
187 |
-
return True, gr.update(value="β
Login successful!", visible=True)
|
188 |
else:
|
189 |
-
return False, gr.update(value="β Invalid email or password.", visible=True)
|
190 |
|
191 |
def handle_logout():
|
192 |
-
return False, "", "",
|
193 |
|
194 |
def handle_signup(name, phone, email, gender, password):
|
195 |
msg = register_user(name, phone, email, gender, password)
|
@@ -198,19 +197,16 @@ with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as
|
|
198 |
else:
|
199 |
return gr.update(value=msg, visible=True), name, phone, email, gender, password, gr.update(open=True)
|
200 |
|
201 |
-
login_btn.click(fn=handle_login, inputs=[email_login, password_login], outputs=[is_logged_in, message_output])
|
202 |
-
logout_btn.click(fn=handle_logout, inputs=[], outputs=[is_logged_in, email_login, password_login,
|
203 |
-
|
204 |
-
|
205 |
-
fn=update_ui_on_auth_change,
|
206 |
-
inputs=is_logged_in,
|
207 |
-
outputs=[login_tab, detect_tab, home_tab, message_output, tabs]
|
208 |
-
)
|
209 |
signup_btn.click(fn=handle_signup, inputs=[name_signup, phone_signup, email_signup, gender_signup, password_signup],
|
210 |
outputs=[message_output, name_signup, phone_signup, email_signup, gender_signup, password_signup, signup_accordion])
|
211 |
predict_btn.click(fn=predict_image, inputs=image_input, outputs=result)
|
212 |
|
213 |
-
demo.load(lambda: False, None, [is_logged_in])
|
|
|
214 |
|
215 |
if __name__ == "__main__":
|
216 |
demo.launch()
|
|
|
102 |
COMMUNITY_TAB_NAME = "π Community"
|
103 |
GUIDE_TAB_NAME = "π User Guide"
|
104 |
|
|
|
|
|
105 |
with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as demo:
|
106 |
is_logged_in = gr.State(False)
|
107 |
+
selected_tab = gr.State(HOME_TAB_NAME)
|
108 |
|
109 |
with gr.Tabs() as tabs:
|
110 |
with gr.Tab(HOME_TAB_NAME, visible=True) as home_tab:
|
|
|
166 |
def update_ui_on_auth_change(logged_in_status):
|
167 |
if logged_in_status:
|
168 |
return (
|
169 |
+
gr.update(visible=False),
|
170 |
+
gr.update(visible=True),
|
171 |
+
gr.update(visible=False),
|
172 |
gr.update(value="β
Login successful!", visible=True),
|
173 |
+
DETECT_TAB_NAME
|
174 |
)
|
175 |
else:
|
176 |
return (
|
177 |
+
gr.update(visible=True),
|
178 |
+
gr.update(visible=False),
|
179 |
+
gr.update(visible=True),
|
180 |
gr.update(value="", visible=False),
|
181 |
+
LOGIN_TAB_NAME
|
182 |
)
|
183 |
|
184 |
def handle_login(email, password):
|
185 |
if login_user(email, password):
|
186 |
+
return True, gr.update(value="β
Login successful!", visible=True), DETECT_TAB_NAME
|
187 |
else:
|
188 |
+
return False, gr.update(value="β Invalid email or password.", visible=True), LOGIN_TAB_NAME
|
189 |
|
190 |
def handle_logout():
|
191 |
+
return False, "", "", LOGIN_TAB_NAME
|
192 |
|
193 |
def handle_signup(name, phone, email, gender, password):
|
194 |
msg = register_user(name, phone, email, gender, password)
|
|
|
197 |
else:
|
198 |
return gr.update(value=msg, visible=True), name, phone, email, gender, password, gr.update(open=True)
|
199 |
|
200 |
+
login_btn.click(fn=handle_login, inputs=[email_login, password_login], outputs=[is_logged_in, message_output, selected_tab])
|
201 |
+
logout_btn.click(fn=handle_logout, inputs=[], outputs=[is_logged_in, email_login, password_login, selected_tab])
|
202 |
+
is_logged_in.change(fn=update_ui_on_auth_change, inputs=is_logged_in,
|
203 |
+
outputs=[login_tab, detect_tab, home_tab, message_output, selected_tab])
|
|
|
|
|
|
|
|
|
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])
|
206 |
predict_btn.click(fn=predict_image, inputs=image_input, outputs=result)
|
207 |
|
208 |
+
demo.load(lambda: (False, HOME_TAB_NAME), None, [is_logged_in, selected_tab])
|
209 |
+
selected_tab.change(fn=None, inputs=selected_tab, outputs=None, _js="(tab) => window.gradioApp().getElementById('tabs').querySelector(`[aria-label='${tab}']`).click()")
|
210 |
|
211 |
if __name__ == "__main__":
|
212 |
demo.launch()
|