Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,21 +14,38 @@ eff_path = hf_hub_download(repo_id="Zeyadd-Mostaffa/deepfake-image-detector", fi
|
|
14 |
xcp_model = load_model(xcp_path)
|
15 |
eff_model = load_model(eff_path)
|
16 |
|
17 |
-
def predict(
|
18 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
xcp_img = cv2.resize(image, (299, 299))
|
20 |
eff_img = cv2.resize(image, (224, 224))
|
|
|
|
|
21 |
xcp_tensor = xcp_pre(xcp_img.astype(np.float32))[np.newaxis, ...]
|
22 |
eff_tensor = eff_pre(eff_img.astype(np.float32))[np.newaxis, ...]
|
23 |
-
|
24 |
# Predict
|
25 |
xcp_pred = xcp_model.predict(xcp_tensor, verbose=0).flatten()[0]
|
26 |
eff_pred = eff_model.predict(eff_tensor, verbose=0).flatten()[0]
|
27 |
avg_pred = (xcp_pred + eff_pred) / 2
|
|
|
28 |
label = "Real" if avg_pred > 0.5 else "Fake"
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
32 |
|
33 |
iface = gr.Interface(
|
34 |
fn=predict,
|
|
|
14 |
xcp_model = load_model(xcp_path)
|
15 |
eff_model = load_model(eff_path)
|
16 |
|
17 |
+
def predict(image_path):
|
18 |
+
# Read the image from file path
|
19 |
+
image = cv2.imread(image_path)
|
20 |
+
|
21 |
+
# Check if loading failed
|
22 |
+
if image is None:
|
23 |
+
raise ValueError("Failed to load image. Make sure the input is an image file.")
|
24 |
+
|
25 |
+
# Convert BGR to RGB (OpenCV loads images in BGR)
|
26 |
+
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
27 |
+
|
28 |
+
# Resize for each model
|
29 |
xcp_img = cv2.resize(image, (299, 299))
|
30 |
eff_img = cv2.resize(image, (224, 224))
|
31 |
+
|
32 |
+
# Preprocess
|
33 |
xcp_tensor = xcp_pre(xcp_img.astype(np.float32))[np.newaxis, ...]
|
34 |
eff_tensor = eff_pre(eff_img.astype(np.float32))[np.newaxis, ...]
|
35 |
+
|
36 |
# Predict
|
37 |
xcp_pred = xcp_model.predict(xcp_tensor, verbose=0).flatten()[0]
|
38 |
eff_pred = eff_model.predict(eff_tensor, verbose=0).flatten()[0]
|
39 |
avg_pred = (xcp_pred + eff_pred) / 2
|
40 |
+
|
41 |
label = "Real" if avg_pred > 0.5 else "Fake"
|
42 |
+
|
43 |
+
return {
|
44 |
+
"label": label,
|
45 |
+
"average": round(avg_pred, 3),
|
46 |
+
"xception": round(xcp_pred, 3),
|
47 |
+
"efficientnet": round(eff_pred, 3)
|
48 |
+
}
|
49 |
|
50 |
iface = gr.Interface(
|
51 |
fn=predict,
|