File size: 777 Bytes
6b9b555
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import numpy as np
from tensorflow.keras.models import load_model
from PIL import Image

# Load pre-uploaded model
model = load_model("xception_model.h5")

def preprocess_image(image):
    image = image.resize((299, 299)).convert("RGB")  # ✅ Fix: match Xception input shape
    img_array = np.array(image) / 255.0
    return np.expand_dims(img_array, axis=0)

def predict(image):
    img = preprocess_image(image)
    prob = model.predict(img)[0][0]
    label = "REAL" if prob >= 0.5 else "FAKE"
    return {"REAL": 1 - prob, "FAKE": prob}, f"Prediction: {label}"

demo = gr.Interface(
    fn=predict,
    inputs=gr.Image(type="pil"),
    outputs=[gr.Label(num_top_classes=2), gr.Text()],
    title="Deepfake Detection (Xception Model)"
)

demo.launch()