Spaces:
Sleeping
Sleeping
File size: 1,198 Bytes
6b9b555 3ac8be5 4aae750 6b9b555 3ac8be5 6b9b555 a3131e2 3ac8be5 6b9b555 a3131e2 6b9b555 4aae750 a3131e2 4aae750 a3131e2 4aae750 ecd8bf8 fb886c0 6b9b555 a3131e2 3ac8be5 6b9b555 3ac8be5 6b9b555 3ac8be5 |
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 |
import gradio as gr
import numpy as np
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.image import img_to_array
from tensorflow.keras.applications.xception import preprocess_input
from PIL import Image
from huggingface_hub import hf_hub_download
# Download and load the model
model_path = hf_hub_download(repo_id="Zeyadd-Mostaffa/cv_GP", filename="xception_model.h5")
model = load_model(model_path)
# Inference function
def predict(image):
image = image.resize((299, 299)) # Resize to match model input
image = img_to_array(image) # Convert to numpy array
image = np.expand_dims(image, axis=0) # Add batch dimension
image = preprocess_input(image) # Apply Xception preprocessing (important fix!)
prob = model.predict(image)[0][0]
# Based on training: label 0 = Fake, label 1 = Real
label = "Real" if prob > 0.5 else "Fake"
confidence = round(float(prob if prob > 0.5 else 1 - prob), 3)
return f"{label} ({confidence * 100:.1f}%)"
# Gradio interface
iface = gr.Interface(
fn=predict,
inputs=gr.Image(type="pil"),
outputs=gr.Text(),
title="Deepfake Detection (Xception Model)"
)
iface.launch()
|