File size: 1,018 Bytes
6b9b555
 
 
3ac8be5
6b9b555
3ac8be5
6b9b555
3ac8be5
 
 
6b9b555
3ac8be5
6b9b555
3ac8be5
 
 
 
 
 
 
 
 
 
6b9b555
3ac8be5
 
6b9b555
 
3ac8be5
6b9b555
 
 
3ac8be5
 
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
30
31
32
33
34
35
36
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()