Spaces:
Sleeping
Sleeping
Update dashboard.py
Browse files- dashboard.py +64 -33
dashboard.py
CHANGED
@@ -14,7 +14,7 @@ from pages import about, community, user_guide
|
|
14 |
|
15 |
# --- Config ---
|
16 |
SUPABASE_URL = "https://fpbuhzbdtzwomjwytqul.supabase.co"
|
17 |
-
SUPABASE_API_KEY = "
|
18 |
SUPABASE_TABLE = "user_details"
|
19 |
|
20 |
headers = {
|
@@ -30,19 +30,14 @@ np.seterr(all='ignore')
|
|
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 |
-
|
40 |
-
warnings.simplefilter("ignore")
|
41 |
-
dummy_model.save(MODEL_PATH)
|
42 |
|
43 |
-
|
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)
|
@@ -63,17 +58,39 @@ def predict_image(image):
|
|
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 |
-
|
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"
|
@@ -81,22 +98,21 @@ with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as
|
|
81 |
COMMUNITY_TAB_NAME = "π Community"
|
82 |
GUIDE_TAB_NAME = "π User Guide"
|
83 |
|
84 |
-
|
85 |
-
|
86 |
-
with tabs:
|
87 |
with gr.Tab(HOME_TAB_NAME) as home_tab:
|
88 |
-
with gr.Row(
|
89 |
with gr.Column():
|
90 |
gr.Markdown("""
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
""",
|
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")
|
@@ -110,11 +126,26 @@ with gr.Blocks(theme=gr.themes.Soft(), title="VerifiAI - Deepfake Detector") as
|
|
110 |
with gr.Tab(COMMUNITY_TAB_NAME): community.layout()
|
111 |
with gr.Tab(GUIDE_TAB_NAME): user_guide.layout()
|
112 |
|
113 |
-
#
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
predict_btn.click(fn=predict_image, inputs=image_input, outputs=result)
|
117 |
-
|
|
|
118 |
|
119 |
if __name__ == "__main__":
|
120 |
demo.launch()
|
|
|
14 |
|
15 |
# --- Config ---
|
16 |
SUPABASE_URL = "https://fpbuhzbdtzwomjwytqul.supabase.co"
|
17 |
+
SUPABASE_API_KEY = "your-api-key"
|
18 |
SUPABASE_TABLE = "user_details"
|
19 |
|
20 |
headers = {
|
|
|
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)
|
|
|
58 |
label = "β
Real Image" if prediction >= 0.5 else "β οΈ Fake Image"
|
59 |
return f"{label} (Confidence: {confidence:.2%})"
|
60 |
|
61 |
+
def register_user(name, phone, email, gender, password):
|
62 |
+
if not all([name, phone, email, gender, password]):
|
63 |
+
return "β All fields are required for signup."
|
64 |
+
if not is_valid_email(email): return "β Invalid email format."
|
65 |
+
if not is_valid_phone(phone): return "β Phone must be 10 digits."
|
66 |
+
|
67 |
+
query_url = f"{SUPABASE_URL}/rest/v1/{SUPABASE_TABLE}?email=eq.{email}"
|
68 |
+
r = requests.get(query_url, headers=headers)
|
69 |
+
if r.status_code == 200 and len(r.json()) > 0:
|
70 |
+
return "β οΈ Email already registered."
|
71 |
+
|
72 |
+
hashed_pw = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode()
|
73 |
+
data = {
|
74 |
+
"name": name,
|
75 |
+
"phone": phone,
|
76 |
+
"email": email,
|
77 |
+
"gender": gender,
|
78 |
+
"password": hashed_pw
|
79 |
+
}
|
80 |
+
r = requests.post(f"{SUPABASE_URL}/rest/v1/{SUPABASE_TABLE}", headers=headers, data=json.dumps(data))
|
81 |
+
return "β
Registration successful! Please log in." if r.status_code == 201 else "β Error during registration."
|
82 |
+
|
83 |
+
def login_user(email, password):
|
84 |
+
url = f"{SUPABASE_URL}/rest/v1/{SUPABASE_TABLE}?email=eq.{email}"
|
85 |
+
r = requests.get(url, headers=headers)
|
86 |
+
if r.status_code == 200 and r.json():
|
87 |
+
stored_hash = r.json()[0]["password"]
|
88 |
+
return bcrypt.checkpw(password.encode(), stored_hash.encode())
|
89 |
+
return False
|
90 |
+
|
91 |
# --- UI ---
|
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_NAME = "π Home"
|
96 |
DETECT_TAB_NAME = "π§ͺ Detect Deepfake"
|
|
|
98 |
COMMUNITY_TAB_NAME = "π Community"
|
99 |
GUIDE_TAB_NAME = "π User Guide"
|
100 |
|
101 |
+
with gr.Tabs(selected=HOME_TAB_NAME) as tabs:
|
102 |
+
# --- Home Tab (Intro Page) ---
|
|
|
103 |
with gr.Tab(HOME_TAB_NAME) as home_tab:
|
104 |
+
with gr.Row():
|
105 |
with gr.Column():
|
106 |
gr.Markdown("""
|
107 |
+
<div class="home-content">
|
108 |
+
<h1>ποΈβπ¨οΈ Welcome to VerifiAI</h1>
|
109 |
+
<p>Your trusted assistant for detecting deepfakes in images using AI.</p>
|
110 |
+
<p>π Upload images, analyze authenticity, and learn how deepfakes work.</p>
|
111 |
+
<p>π Use the tabs above to get started.</p>
|
112 |
+
</div>
|
113 |
+
""", elem_id="home-markdown")
|
114 |
+
|
115 |
+
with gr.Tab(DETECT_TAB_NAME, visible=True) as detect_tab:
|
116 |
with gr.Row():
|
117 |
gr.Markdown("## Deepfake Detector")
|
118 |
logout_btn = gr.Button("Logout")
|
|
|
126 |
with gr.Tab(COMMUNITY_TAB_NAME): community.layout()
|
127 |
with gr.Tab(GUIDE_TAB_NAME): user_guide.layout()
|
128 |
|
129 |
+
# --- CSS Styling ---
|
130 |
+
gr.HTML("""
|
131 |
+
<style>
|
132 |
+
#home-markdown {
|
133 |
+
display: flex;
|
134 |
+
justify-content: center;
|
135 |
+
align-items: center;
|
136 |
+
height: 70vh;
|
137 |
+
text-align: center;
|
138 |
+
}
|
139 |
+
</style>
|
140 |
+
""")
|
141 |
+
|
142 |
+
# --- Callbacks ---
|
143 |
+
def handle_logout():
|
144 |
+
return False, "", ""
|
145 |
|
146 |
predict_btn.click(fn=predict_image, inputs=image_input, outputs=result)
|
147 |
+
logout_btn.click(fn=handle_logout, inputs=[], outputs=[is_logged_in, image_input, result])
|
148 |
+
demo.load(fn=lambda: False, outputs=is_logged_in)
|
149 |
|
150 |
if __name__ == "__main__":
|
151 |
demo.launch()
|