File size: 1,632 Bytes
e73e2a2
 
3a2cd79
e73e2a2
3a2cd79
e6fe7fe
3a2cd79
 
e73e2a2
eaa1a24
ce59aac
e73e2a2
 
 
 
3a2cd79
 
ce59aac
93ce865
 
e6fe7fe
ce59aac
e73e2a2
 
93ce865
ce59aac
93ce865
4ab3d47
 
 
 
3a2cd79
ce59aac
 
3a2cd79
ce59aac
e73e2a2
3a2cd79
777870a
ce59aac
2bf05af
 
e73e2a2
 
9edd18a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
44
45
46
import os
import cv2
import numpy as np
import gradio as gr
import tensorflow as tf
from tensorflow.keras.models import load_model
from tensorflow.keras.applications.xception import preprocess_input as xcp_pre
from tensorflow.keras.applications.efficientnet import preprocess_input as eff_pre
from huggingface_hub import hf_hub_download

# Load models
xcp_path = hf_hub_download(repo_id="Zeyadd-Mostaffa/deepfake-image-detector", filename="xception_model.h5")
eff_path = hf_hub_download(repo_id="Zeyadd-Mostaffa/deepfake-image-detector", filename="efficientnet_model.h5")
xcp_model = load_model(xcp_path)
eff_model = load_model(eff_path)

def predict(image):
    # Resize for each model
    xcp_img = cv2.resize(image, (299, 299))
    eff_img = cv2.resize(image, (224, 224))

    # Preprocess
    xcp_tensor = xcp_pre(xcp_img.astype(np.float32))[np.newaxis, ...]
    eff_tensor = eff_pre(eff_img.astype(np.float32))[np.newaxis, ...]

    # Predict
    xcp_pred = xcp_model.predict(xcp_tensor, verbose=0).flatten()[0]
    eff_pred = eff_model.predict(eff_tensor, verbose=0).flatten()[0]

    avg_pred = (xcp_pred + eff_pred) / 2
    label = "Real" if avg_pred > 0.5 else "Fake"

    # βœ… Simplest format: just the label (for gradio_client compatibility)
    return label

# βœ… Output changed from gr.Label β†’ gr.Textbox to avoid JSON schema issues
interface = gr.Interface(
    fn=predict,
    inputs=gr.Image(type="numpy", label="Upload Image"),
    outputs=gr.Textbox(label="Prediction"),
    title="Deepfake Image Detector",
    description="Upload a full image. The model classifies it as real or fake."
)

interface.launch()