Zeyadd-Mostaffa's picture
Update app.py
3ac8be5 verified
raw
history blame
1.02 kB
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 PIL import Image
from huggingface_hub import hf_hub_download
# Download the model from the Hugging Face model hub
model_path = hf_hub_download(repo_id="Zeyadd-Mostaffa/cv_GP", filename="xception_model.h5")
model = load_model(model_path)
# Preprocessing and prediction
def predict(image):
# Resize image to expected shape (299x299x3 for Xception)
image = image.resize((299, 299))
image = img_to_array(image)
image = np.expand_dims(image, axis=0)
image = image / 255.0 # Normalize
prob = model.predict(image)[0][0]
label = "Fake" if prob > 0.5 else "Real"
confidence = round(float(prob if prob > 0.5 else 1 - prob), 3)
return f"{label} ({confidence})"
# Gradio UI
iface = gr.Interface(
fn=predict,
inputs=gr.Image(type="pil"),
outputs=gr.Text(),
title="Deepfake Detection (Xception Model)"
)
iface.launch()