Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,17 +8,17 @@ 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 |
-
#
|
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(
|
18 |
try:
|
19 |
# Resize input
|
20 |
-
xcp_img = cv2.resize(
|
21 |
-
eff_img = cv2.resize(
|
22 |
|
23 |
# Preprocess for each model
|
24 |
xcp_tensor = xcp_pre(xcp_img.astype(np.float32))[np.newaxis, ...]
|
@@ -29,20 +29,18 @@ def predict(image):
|
|
29 |
eff_pred = eff_model.predict(eff_tensor, verbose=0).flatten()[0]
|
30 |
|
31 |
avg_pred = (xcp_pred + eff_pred) / 2
|
32 |
-
|
33 |
-
|
34 |
-
# ✅ Return plain string (must be str type)
|
35 |
-
return str(label)
|
36 |
|
37 |
except Exception as e:
|
38 |
return "Error: " + str(e)
|
39 |
|
40 |
-
|
|
|
41 |
fn=predict,
|
42 |
-
inputs=gr.Image(type="numpy"
|
43 |
-
outputs=gr.Textbox(
|
44 |
-
|
45 |
-
description="Upload a full image. The model classifies it as real or fake."
|
46 |
)
|
47 |
|
48 |
-
|
|
|
|
8 |
from tensorflow.keras.applications.efficientnet import preprocess_input as eff_pre
|
9 |
from huggingface_hub import hf_hub_download
|
10 |
|
11 |
+
# 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(img):
|
18 |
try:
|
19 |
# Resize input
|
20 |
+
xcp_img = cv2.resize(img, (299, 299))
|
21 |
+
eff_img = cv2.resize(img, (224, 224))
|
22 |
|
23 |
# Preprocess for each model
|
24 |
xcp_tensor = xcp_pre(xcp_img.astype(np.float32))[np.newaxis, ...]
|
|
|
29 |
eff_pred = eff_model.predict(eff_tensor, verbose=0).flatten()[0]
|
30 |
|
31 |
avg_pred = (xcp_pred + eff_pred) / 2
|
32 |
+
return "Real" if avg_pred > 0.5 else "Fake"
|
|
|
|
|
|
|
33 |
|
34 |
except Exception as e:
|
35 |
return "Error: " + str(e)
|
36 |
|
37 |
+
# ✅ Use literal type-safe components
|
38 |
+
demo = gr.Interface(
|
39 |
fn=predict,
|
40 |
+
inputs=gr.Image(type="numpy"),
|
41 |
+
outputs=gr.Textbox(),
|
42 |
+
allow_flagging="never"
|
|
|
43 |
)
|
44 |
|
45 |
+
if __name__ == "__main__":
|
46 |
+
demo.launch()
|