Spaces:
Sleeping
Sleeping
Update dashboard.py
Browse files- dashboard.py +87 -57
dashboard.py
CHANGED
|
@@ -30,14 +30,19 @@ np.seterr(all='ignore')
|
|
| 30 |
|
| 31 |
MODEL_PATH = "model_15_64.h5"
|
| 32 |
if not os.path.exists(MODEL_PATH):
|
|
|
|
| 33 |
dummy_model = tf.keras.Sequential([
|
| 34 |
tf.keras.layers.Input(shape=(128, 128, 3)),
|
| 35 |
tf.keras.layers.Flatten(),
|
| 36 |
tf.keras.layers.Dense(1, activation='sigmoid')
|
| 37 |
])
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
| 42 |
# --- Helpers ---
|
| 43 |
def is_valid_email(email): return re.match(r"[^@]+@[^@]+\.[^@]+", email)
|
|
@@ -92,62 +97,60 @@ def login_user(email, password):
|
|
| 92 |
with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as demo:
|
| 93 |
is_logged_in = gr.State(False)
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
with gr.Tabs(selected=HOME_TAB) as tabs:
|
| 103 |
-
# --- Home Tab ---
|
| 104 |
-
with gr.Tab(HOME_TAB):
|
| 105 |
-
gr.Markdown("""
|
| 106 |
-
<div class="home-content">
|
| 107 |
-
<h1>ποΈβπ¨οΈ Welcome to VerifiAI</h1>
|
| 108 |
-
<p>Your trusted assistant for detecting deepfakes in images using AI.</p>
|
| 109 |
-
<p>π Upload images, analyze authenticity, and learn how deepfakes work.</p>
|
| 110 |
-
<p>π Use the tabs above to get started.</p>
|
| 111 |
-
</div>
|
| 112 |
-
""", elem_id="home-markdown")
|
| 113 |
-
|
| 114 |
-
# --- Login Tab ---
|
| 115 |
-
with gr.Tab(LOGIN_TAB):
|
| 116 |
-
with gr.Row():
|
| 117 |
-
with gr.Column():
|
| 118 |
-
email_input = gr.Textbox(label="Email", placeholder="Enter your email")
|
| 119 |
-
password_input = gr.Textbox(label="Password", type="password", placeholder="Enter your password")
|
| 120 |
-
login_button = gr.Button("Login", variant="primary")
|
| 121 |
-
login_msg = gr.Textbox(label="Login Status", interactive=False)
|
| 122 |
|
|
|
|
|
|
|
|
|
|
| 123 |
with gr.Row():
|
| 124 |
with gr.Column():
|
| 125 |
-
gr.Markdown("
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
with gr.Row():
|
| 137 |
gr.Markdown("## Deepfake Detector")
|
| 138 |
logout_btn = gr.Button("Logout")
|
| 139 |
with gr.Row():
|
| 140 |
-
image_input = gr.Image(type="pil", label="Upload Image")
|
| 141 |
-
with gr.Column():
|
| 142 |
result = gr.Textbox(label="Prediction Result", interactive=False)
|
| 143 |
predict_btn = gr.Button("Predict", variant="primary")
|
| 144 |
|
| 145 |
-
|
| 146 |
-
with gr.Tab(
|
| 147 |
-
with gr.Tab(
|
| 148 |
-
with gr.Tab(GUIDE_TAB): user_guide.layout()
|
| 149 |
|
| 150 |
-
# --- CSS
|
| 151 |
gr.HTML("""
|
| 152 |
<style>
|
| 153 |
#home-markdown {
|
|
@@ -160,20 +163,47 @@ with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as
|
|
| 160 |
</style>
|
| 161 |
""")
|
| 162 |
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
def handle_login(email, password):
|
| 165 |
-
|
| 166 |
-
|
|
|
|
|
|
|
| 167 |
|
| 168 |
def handle_logout():
|
| 169 |
-
return False, "", ""
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
predict_btn.click(fn=predict_image, inputs=image_input, outputs=result)
|
| 175 |
|
| 176 |
-
demo.load(fn=lambda: False, outputs=is_logged_in)
|
| 177 |
-
|
| 178 |
if __name__ == "__main__":
|
| 179 |
demo.launch()
|
|
|
|
| 30 |
|
| 31 |
MODEL_PATH = "model_15_64.h5"
|
| 32 |
if not os.path.exists(MODEL_PATH):
|
| 33 |
+
print(f"Model file '{MODEL_PATH}' not found. Creating a dummy model for testing.")
|
| 34 |
dummy_model = tf.keras.Sequential([
|
| 35 |
tf.keras.layers.Input(shape=(128, 128, 3)),
|
| 36 |
tf.keras.layers.Flatten(),
|
| 37 |
tf.keras.layers.Dense(1, activation='sigmoid')
|
| 38 |
])
|
| 39 |
+
with warnings.catch_warnings():
|
| 40 |
+
warnings.simplefilter("ignore")
|
| 41 |
+
dummy_model.save(MODEL_PATH)
|
| 42 |
|
| 43 |
+
with warnings.catch_warnings():
|
| 44 |
+
warnings.simplefilter("ignore")
|
| 45 |
+
deepfake_model = tf.keras.models.load_model(MODEL_PATH)
|
| 46 |
|
| 47 |
# --- Helpers ---
|
| 48 |
def is_valid_email(email): return re.match(r"[^@]+@[^@]+\.[^@]+", email)
|
|
|
|
| 97 |
with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as demo:
|
| 98 |
is_logged_in = gr.State(False)
|
| 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 |
+
with gr.Tabs(selected=HOME_TAB_NAME) as tabs:
|
| 108 |
+
# --- Home Tab (Intro Page) ---
|
| 109 |
+
with gr.Tab(HOME_TAB_NAME) as home_tab:
|
| 110 |
with gr.Row():
|
| 111 |
with gr.Column():
|
| 112 |
+
gr.Markdown("""
|
| 113 |
+
<div class="home-content">
|
| 114 |
+
<h1>ποΈβπ¨οΈ Welcome to VerifiAI</h1>
|
| 115 |
+
<p>Your trusted assistant for detecting deepfakes in images using AI.</p>
|
| 116 |
+
<p>π Upload images, analyze authenticity, and learn how deepfakes work.</p>
|
| 117 |
+
<p>π Use the tabs above to get started.</p>
|
| 118 |
+
</div>
|
| 119 |
+
""", elem_id="home-markdown")
|
| 120 |
+
|
| 121 |
+
with gr.Tab(LOGIN_TAB_NAME) as login_tab:
|
| 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.")
|
| 125 |
+
with gr.Column(scale=2):
|
| 126 |
+
gr.Markdown("### Login or Sign Up")
|
| 127 |
+
message_output = gr.Markdown(visible=False)
|
| 128 |
+
email_login = gr.Textbox(label="Email")
|
| 129 |
+
password_login = gr.Textbox(label="Password", type="password")
|
| 130 |
+
login_btn = gr.Button("Login", variant="primary")
|
| 131 |
+
with gr.Accordion("New User? Click here to Sign Up", open=False) as signup_accordion:
|
| 132 |
+
name_signup = gr.Textbox(label="Name")
|
| 133 |
+
phone_signup = gr.Textbox(label="Phone (10 digits)")
|
| 134 |
+
email_signup = gr.Textbox(label="Email")
|
| 135 |
+
gender_signup = gr.Dropdown(label="Gender", choices=["Male", "Female", "Other"])
|
| 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")
|
| 143 |
with gr.Row():
|
| 144 |
+
image_input = gr.Image(type="pil", label="Upload Image", scale=1)
|
| 145 |
+
with gr.Column(scale=1):
|
| 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 |
+
# --- CSS Styling ---
|
| 154 |
gr.HTML("""
|
| 155 |
<style>
|
| 156 |
#home-markdown {
|
|
|
|
| 163 |
</style>
|
| 164 |
""")
|
| 165 |
|
| 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(selected=DETECT_TAB_NAME),
|
| 172 |
+
gr.update(value="β
Login successful!", visible=True)
|
| 173 |
+
)
|
| 174 |
+
else:
|
| 175 |
+
return (
|
| 176 |
+
gr.update(visible=True),
|
| 177 |
+
gr.update(visible=False),
|
| 178 |
+
gr.update(selected=LOGIN_TAB_NAME),
|
| 179 |
+
gr.update(value="", visible=False)
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
def handle_login(email, password):
|
| 183 |
+
if login_user(email, password):
|
| 184 |
+
return True, gr.update(value="β
Login successful!", visible=True)
|
| 185 |
+
else:
|
| 186 |
+
return False, gr.update(value="β Invalid email or password.", visible=True)
|
| 187 |
|
| 188 |
def handle_logout():
|
| 189 |
+
return False, "", ""
|
| 190 |
+
|
| 191 |
+
def handle_signup(name, phone, email, gender, password):
|
| 192 |
+
msg = register_user(name, phone, email, gender, password)
|
| 193 |
+
if msg.startswith("β
"):
|
| 194 |
+
return gr.update(value=msg, visible=True), "", "", "", "", "", gr.update(open=False)
|
| 195 |
+
else:
|
| 196 |
+
return gr.update(value=msg, visible=True), name, phone, email, gender, password, gr.update(open=True)
|
| 197 |
+
|
| 198 |
+
login_btn.click(fn=handle_login, inputs=[email_login, password_login], outputs=[is_logged_in, message_output])
|
| 199 |
+
logout_btn.click(fn=handle_logout, inputs=[], outputs=[is_logged_in, email_login, password_login])
|
| 200 |
+
is_logged_in.change(fn=update_ui_on_auth_change, inputs=is_logged_in, outputs=[login_tab, detect_tab, tabs, message_output])
|
| 201 |
+
signup_btn.click(
|
| 202 |
+
fn=handle_signup,
|
| 203 |
+
inputs=[name_signup, phone_signup, email_signup, gender_signup, password_signup],
|
| 204 |
+
outputs=[message_output, name_signup, phone_signup, email_signup, gender_signup, password_signup, signup_accordion]
|
| 205 |
+
)
|
| 206 |
predict_btn.click(fn=predict_image, inputs=image_input, outputs=result)
|
| 207 |
|
|
|
|
|
|
|
| 208 |
if __name__ == "__main__":
|
| 209 |
demo.launch()
|