Spaces:
Sleeping
Sleeping
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() | |