Spaces:
Running
Running
Update dashboard.py
Browse files- dashboard.py +24 -111
dashboard.py
CHANGED
@@ -63,82 +63,40 @@ def predict_image(image):
|
|
63 |
label = "β
Real Image" if prediction >= 0.5 else "β οΈ Fake Image"
|
64 |
return f"{label} (Confidence: {confidence:.2%})"
|
65 |
|
66 |
-
def register_user(name, phone, email, gender, password):
|
67 |
-
if not all([name, phone, email, gender, password]):
|
68 |
-
return "β All fields are required for signup."
|
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:
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
HOME_TAB_NAME = "π Home"
|
101 |
-
LOGIN_TAB_NAME = "π Login"
|
102 |
DETECT_TAB_NAME = "π§ͺ Detect Deepfake"
|
103 |
ABOUT_TAB_NAME = "βΉοΈ About"
|
104 |
COMMUNITY_TAB_NAME = "π Community"
|
105 |
GUIDE_TAB_NAME = "π User Guide"
|
106 |
|
107 |
-
|
108 |
-
|
|
|
109 |
with gr.Tab(HOME_TAB_NAME) as home_tab:
|
110 |
-
with gr.
|
111 |
-
gr.
|
112 |
-
|
113 |
-
|
|
|
114 |
|
115 |
-
|
116 |
|
117 |
-
|
118 |
-
|
119 |
-
go_login_btn = gr.Button("π Go to Login")
|
120 |
|
121 |
-
|
122 |
-
with gr.Tab(LOGIN_TAB_NAME) as login_tab:
|
123 |
-
with gr.Row():
|
124 |
-
with gr.Column(scale=1):
|
125 |
-
gr.Markdown("## Welcome!", "Login to access the detector, or sign up for a new account.")
|
126 |
-
with gr.Column(scale=2):
|
127 |
-
gr.Markdown("### Login or Sign Up")
|
128 |
-
message_output = gr.Markdown(visible=False)
|
129 |
-
email_login = gr.Textbox(label="Email")
|
130 |
-
password_login = gr.Textbox(label="Password", type="password")
|
131 |
-
login_btn = gr.Button("Login", variant="primary")
|
132 |
-
with gr.Accordion("New User? Click here to Sign Up", open=False) as signup_accordion:
|
133 |
-
name_signup = gr.Textbox(label="Name")
|
134 |
-
phone_signup = gr.Textbox(label="Phone (10 digits)")
|
135 |
-
email_signup = gr.Textbox(label="Email")
|
136 |
-
gender_signup = gr.Dropdown(label="Gender", choices=["Male", "Female", "Other"])
|
137 |
-
password_signup = gr.Textbox(label="Create Password", type="password")
|
138 |
-
signup_btn = gr.Button("Sign Up")
|
139 |
-
|
140 |
-
# --- DETECTION TAB ---
|
141 |
-
with gr.Tab(DETECT_TAB_NAME, visible=False) as detect_tab:
|
142 |
with gr.Row():
|
143 |
gr.Markdown("## Deepfake Detector")
|
144 |
logout_btn = gr.Button("Logout")
|
@@ -148,60 +106,15 @@ with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as
|
|
148 |
result = gr.Textbox(label="Prediction Result", interactive=False)
|
149 |
predict_btn = gr.Button("Predict", variant="primary")
|
150 |
|
151 |
-
# --- OTHER TABS ---
|
152 |
with gr.Tab(ABOUT_TAB_NAME): about.layout()
|
153 |
with gr.Tab(COMMUNITY_TAB_NAME): community.layout()
|
154 |
with gr.Tab(GUIDE_TAB_NAME): user_guide.layout()
|
155 |
|
156 |
-
#
|
157 |
-
|
158 |
-
|
159 |
-
return (
|
160 |
-
gr.update(visible=False),
|
161 |
-
gr.update(visible=True),
|
162 |
-
gr.update(selected=GUIDE_TAB_NAME),
|
163 |
-
gr.update(value="β
Login successful!", visible=True)
|
164 |
-
)
|
165 |
-
else:
|
166 |
-
return (
|
167 |
-
gr.update(visible=True),
|
168 |
-
gr.update(visible=False),
|
169 |
-
gr.update(selected=LOGIN_TAB_NAME),
|
170 |
-
gr.update(value="", visible=False)
|
171 |
-
)
|
172 |
-
|
173 |
-
def handle_login(email, password):
|
174 |
-
if login_user(email, password):
|
175 |
-
return True, gr.update(value="β
Login successful!", visible=True)
|
176 |
-
else:
|
177 |
-
return False, gr.update(value="β Invalid email or password.", visible=True)
|
178 |
-
|
179 |
-
def handle_logout():
|
180 |
-
return False, "", ""
|
181 |
-
|
182 |
-
def handle_signup(name, phone, email, gender, password):
|
183 |
-
msg = register_user(name, phone, email, gender, password)
|
184 |
-
if msg.startswith("β
"):
|
185 |
-
return gr.update(value=msg, visible=True), "", "", "", "", "", gr.update(open=False)
|
186 |
-
else:
|
187 |
-
return gr.update(value=msg, visible=True), name, phone, email, gender, password, gr.update(open=True)
|
188 |
-
|
189 |
-
def go_to_login():
|
190 |
-
return gr.update(selected=LOGIN_TAB_NAME)
|
191 |
-
|
192 |
-
# --- Events ---
|
193 |
-
go_login_btn.click(fn=go_to_login, outputs=tabs)
|
194 |
-
login_btn.click(fn=handle_login, inputs=[email_login, password_login], outputs=[is_logged_in, message_output])
|
195 |
-
logout_btn.click(fn=handle_logout, inputs=[], outputs=[is_logged_in, email_login, password_login])
|
196 |
-
is_logged_in.change(fn=update_ui_on_auth_change, inputs=is_logged_in, outputs=[login_tab, detect_tab, tabs, message_output])
|
197 |
-
signup_btn.click(
|
198 |
-
fn=handle_signup,
|
199 |
-
inputs=[name_signup, phone_signup, email_signup, gender_signup, password_signup],
|
200 |
-
outputs=[message_output, name_signup, phone_signup, email_signup, gender_signup, password_signup, signup_accordion]
|
201 |
-
)
|
202 |
predict_btn.click(fn=predict_image, inputs=image_input, outputs=result)
|
203 |
|
204 |
-
demo.load(fn=lambda: False, outputs=is_logged_in)
|
205 |
|
206 |
if __name__ == "__main__":
|
207 |
demo.launch()
|
|
|
63 |
label = "β
Real Image" if prediction >= 0.5 else "β οΈ Fake Image"
|
64 |
return f"{label} (Confidence: {confidence:.2%})"
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
# --- UI ---
|
67 |
with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as demo:
|
68 |
+
# Custom CSS for centering content
|
69 |
+
gr.HTML("""
|
70 |
+
<style>
|
71 |
+
.home-content {
|
72 |
+
text-align: center;
|
73 |
+
margin-top: 100px;
|
74 |
+
}
|
75 |
+
</style>
|
76 |
+
""")
|
77 |
|
78 |
HOME_TAB_NAME = "π Home"
|
|
|
79 |
DETECT_TAB_NAME = "π§ͺ Detect Deepfake"
|
80 |
ABOUT_TAB_NAME = "βΉοΈ About"
|
81 |
COMMUNITY_TAB_NAME = "π Community"
|
82 |
GUIDE_TAB_NAME = "π User Guide"
|
83 |
|
84 |
+
tabs = gr.Tabs()
|
85 |
+
|
86 |
+
with tabs:
|
87 |
with gr.Tab(HOME_TAB_NAME) as home_tab:
|
88 |
+
with gr.Row(align="center", justify="center"):
|
89 |
+
with gr.Column():
|
90 |
+
gr.Markdown("""
|
91 |
+
# ποΈβπ¨οΈ Welcome to VerifiAI
|
92 |
+
Your trusted assistant for detecting deepfakes in images using AI.
|
93 |
|
94 |
+
π Upload images, analyze authenticity, and learn how deepfakes work.
|
95 |
|
96 |
+
π Use the tabs above to get started.
|
97 |
+
""", elem_classes="home-content")
|
|
|
98 |
|
99 |
+
with gr.Tab(DETECT_TAB_NAME) as detect_tab:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
with gr.Row():
|
101 |
gr.Markdown("## Deepfake Detector")
|
102 |
logout_btn = gr.Button("Logout")
|
|
|
106 |
result = gr.Textbox(label="Prediction Result", interactive=False)
|
107 |
predict_btn = gr.Button("Predict", variant="primary")
|
108 |
|
|
|
109 |
with gr.Tab(ABOUT_TAB_NAME): about.layout()
|
110 |
with gr.Tab(COMMUNITY_TAB_NAME): community.layout()
|
111 |
with gr.Tab(GUIDE_TAB_NAME): user_guide.layout()
|
112 |
|
113 |
+
# Ensure Home tab is selected on load
|
114 |
+
demo.load(fn=lambda: gr.update(selected=HOME_TAB_NAME), outputs=tabs)
|
115 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
predict_btn.click(fn=predict_image, inputs=image_input, outputs=result)
|
117 |
|
|
|
118 |
|
119 |
if __name__ == "__main__":
|
120 |
demo.launch()
|