Zeyadd-Mostaffa commited on
Commit
2d50ea0
·
verified ·
1 Parent(s): 123f969

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -8,6 +8,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
  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)
@@ -19,6 +20,7 @@ def predict(image_path):
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,15 +29,16 @@ def predict(image_path):
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
 
 
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_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)
 
20
  return {"label": "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
 
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
+
36
  return {"label": label}
37
 
38
  iface = gr.Interface(
39
  fn=predict,
40
  inputs=gr.Image(type="filepath", label="image_path"),
41
+ outputs=gr.JSON(label="output"),
42
  allow_flagging="never"
43
  )
44