parass13 commited on
Commit
d90562a
Β·
verified Β·
1 Parent(s): 25ce2ec

Update dashboard.py

Browse files
Files changed (1) hide show
  1. 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
- dummy_model.save(MODEL_PATH)
 
 
39
 
40
- deepfake_model = tf.keras.models.load_model(MODEL_PATH)
 
 
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
- HOME_TAB = "🏠 Home"
96
- LOGIN_TAB = "πŸ” Login"
97
- DETECT_TAB = "πŸ§ͺ Detect Deepfake"
98
- ABOUT_TAB = "ℹ️ About"
99
- COMMUNITY_TAB = "🌐 Community"
100
- GUIDE_TAB = "πŸ“˜ User Guide"
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("### Or Sign Up")
126
- name = gr.Textbox(label="Name")
127
- phone = gr.Textbox(label="Phone (10 digits)")
128
- email_reg = gr.Textbox(label="Email")
129
- gender = gr.Radio(["Male", "Female", "Other"], label="Gender")
130
- password_reg = gr.Textbox(label="Password", type="password")
131
- register_btn = gr.Button("Register")
132
- register_msg = gr.Textbox(label="Signup Status", interactive=False)
133
-
134
- # --- Detection Tab (only usable when logged in) ---
135
- with gr.Tab(DETECT_TAB) as detect_tab:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- # --- Static Tabs ---
146
- with gr.Tab(ABOUT_TAB): about.layout()
147
- with gr.Tab(COMMUNITY_TAB): community.layout()
148
- with gr.Tab(GUIDE_TAB): user_guide.layout()
149
 
150
- # --- CSS for center alignment ---
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
- # --- Callbacks ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  def handle_login(email, password):
165
- success = login_user(email, password)
166
- return (success, "βœ… Login successful!" if success else "❌ Login failed.")
 
 
167
 
168
  def handle_logout():
169
- return False, "", "", ""
170
-
171
- login_button.click(fn=handle_login, inputs=[email_input, password_input], outputs=[is_logged_in, login_msg])
172
- register_btn.click(fn=register_user, inputs=[name, phone, email_reg, gender, password_reg], outputs=register_msg)
173
- logout_btn.click(fn=handle_logout, outputs=[is_logged_in, image_input, result, login_msg])
 
 
 
 
 
 
 
 
 
 
 
 
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()