Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,43 +2,40 @@ import os
|
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
import gradio as gr
|
5 |
-
from PIL import Image
|
6 |
import tensorflow as tf
|
7 |
from tensorflow.keras.models import load_model
|
8 |
from tensorflow.keras.applications.xception import preprocess_input as xcp_pre
|
9 |
from tensorflow.keras.applications.efficientnet import preprocess_input as eff_pre
|
10 |
from huggingface_hub import hf_hub_download
|
11 |
|
12 |
-
#
|
13 |
xcp_path = hf_hub_download(repo_id="Zeyadd-Mostaffa/deepfake-image-detector", filename="xception_model.h5")
|
14 |
eff_path = hf_hub_download(repo_id="Zeyadd-Mostaffa/deepfake-image-detector", filename="efficientnet_model.h5")
|
15 |
xcp_model = load_model(xcp_path)
|
16 |
eff_model = load_model(eff_path)
|
17 |
|
18 |
-
def predict(image
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
if __name__ == "__main__":
|
44 |
-
demo.launch()
|
|
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
import gradio as gr
|
|
|
5 |
import tensorflow as tf
|
6 |
from tensorflow.keras.models import load_model
|
7 |
from tensorflow.keras.applications.xception import preprocess_input as xcp_pre
|
8 |
from tensorflow.keras.applications.efficientnet import preprocess_input as eff_pre
|
9 |
from huggingface_hub import hf_hub_download
|
10 |
|
11 |
+
# Download and load models
|
12 |
xcp_path = hf_hub_download(repo_id="Zeyadd-Mostaffa/deepfake-image-detector", filename="xception_model.h5")
|
13 |
eff_path = hf_hub_download(repo_id="Zeyadd-Mostaffa/deepfake-image-detector", filename="efficientnet_model.h5")
|
14 |
xcp_model = load_model(xcp_path)
|
15 |
eff_model = load_model(eff_path)
|
16 |
|
17 |
+
def predict(image):
|
18 |
+
# Use the full image directly (no face extraction)
|
19 |
+
xcp_img = cv2.resize(image, (299, 299))
|
20 |
+
eff_img = cv2.resize(image, (224, 224))
|
21 |
+
|
22 |
+
xcp_tensor = xcp_pre(xcp_img.astype(np.float32))[np.newaxis, ...]
|
23 |
+
eff_tensor = eff_pre(eff_img.astype(np.float32))[np.newaxis, ...]
|
24 |
+
|
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 |
+
|
28 |
+
avg_pred = (xcp_pred + eff_pred) / 2
|
29 |
+
label = "Real" if avg_pred > 0.5 else "Fake"
|
30 |
+
|
31 |
+
return label
|
32 |
+
|
33 |
+
interface = gr.Interface(
|
34 |
+
fn=predict,
|
35 |
+
inputs=gr.Image(type="numpy", label="Upload Image"),
|
36 |
+
outputs=gr.Label(label="Prediction"),
|
37 |
+
title="Deepfake Image Detector",
|
38 |
+
description="Upload a full image. The model classifies it as real or fake."
|
39 |
+
)
|
40 |
+
|
41 |
+
interface.launch()
|
|
|
|