Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,19 +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 |
-
# Load models from Hugging Face Hub
|
12 |
xcp_path = hf_hub_download(repo_id="Zeyadd-Mostaffa/deepfake-image-detector_final", filename="xception_model.h5")
|
13 |
eff_path = hf_hub_download(repo_id="Zeyadd-Mostaffa/deepfake-image-detector_final", filename="efficientnet_model.h5")
|
14 |
xcp_model = load_model(xcp_path)
|
15 |
eff_model = load_model(eff_path)
|
16 |
|
17 |
-
def predict(image_path):
|
18 |
image = cv2.imread(image_path)
|
19 |
if image is None:
|
20 |
-
return "Invalid image"
|
21 |
|
22 |
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
23 |
-
|
24 |
xcp_img = cv2.resize(image, (299, 299))
|
25 |
eff_img = cv2.resize(image, (224, 224))
|
26 |
|
@@ -29,17 +27,16 @@ def predict(image_path): # receives filepath from gr.Image(type="filepath")
|
|
29 |
|
30 |
xcp_pred = xcp_model.predict(xcp_tensor, verbose=0).flatten()[0]
|
31 |
eff_pred = eff_model.predict(eff_tensor, verbose=0).flatten()[0]
|
32 |
-
|
33 |
avg_pred = (xcp_pred + eff_pred) / 2
|
|
|
34 |
label = "Real" if avg_pred > 0.5 else "Fake"
|
35 |
-
return label
|
36 |
|
37 |
iface = gr.Interface(
|
38 |
fn=predict,
|
39 |
inputs=gr.Image(type="filepath", label="image_path"),
|
40 |
-
outputs=gr.
|
41 |
allow_flagging="never"
|
42 |
)
|
43 |
|
44 |
-
|
45 |
iface.launch()
|
|
|
8 |
from tensorflow.keras.applications.efficientnet import preprocess_input as eff_pre
|
9 |
from huggingface_hub import hf_hub_download
|
10 |
|
|
|
11 |
xcp_path = hf_hub_download(repo_id="Zeyadd-Mostaffa/deepfake-image-detector_final", filename="xception_model.h5")
|
12 |
eff_path = hf_hub_download(repo_id="Zeyadd-Mostaffa/deepfake-image-detector_final", filename="efficientnet_model.h5")
|
13 |
xcp_model = load_model(xcp_path)
|
14 |
eff_model = load_model(eff_path)
|
15 |
|
16 |
+
def predict(image_path):
|
17 |
image = cv2.imread(image_path)
|
18 |
if image is None:
|
19 |
+
return {"label": "Invalid image"}
|
20 |
|
21 |
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
|
|
22 |
xcp_img = cv2.resize(image, (299, 299))
|
23 |
eff_img = cv2.resize(image, (224, 224))
|
24 |
|
|
|
27 |
|
28 |
xcp_pred = xcp_model.predict(xcp_tensor, verbose=0).flatten()[0]
|
29 |
eff_pred = eff_model.predict(eff_tensor, verbose=0).flatten()[0]
|
|
|
30 |
avg_pred = (xcp_pred + eff_pred) / 2
|
31 |
+
|
32 |
label = "Real" if avg_pred > 0.5 else "Fake"
|
33 |
+
return {"label": label}
|
34 |
|
35 |
iface = gr.Interface(
|
36 |
fn=predict,
|
37 |
inputs=gr.Image(type="filepath", label="image_path"),
|
38 |
+
outputs=gr.JSON(label="output"), # ✅ Safe output
|
39 |
allow_flagging="never"
|
40 |
)
|
41 |
|
|
|
42 |
iface.launch()
|