Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,35 @@
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
from tensorflow.keras.models import load_model
|
|
|
4 |
from PIL import Image
|
|
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
def preprocess_image(image):
|
10 |
-
image = image.resize((299, 299)).convert("RGB") # ✅ Fix: match Xception input shape
|
11 |
-
img_array = np.array(image) / 255.0
|
12 |
-
return np.expand_dims(img_array, axis=0)
|
13 |
|
|
|
14 |
def predict(image):
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
|
|
21 |
fn=predict,
|
22 |
inputs=gr.Image(type="pil"),
|
23 |
-
outputs=
|
24 |
title="Deepfake Detection (Xception Model)"
|
25 |
)
|
26 |
|
27 |
-
|
|
|
28 |
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
from tensorflow.keras.models import load_model
|
4 |
+
from tensorflow.keras.preprocessing.image import img_to_array
|
5 |
from PIL import Image
|
6 |
+
from huggingface_hub import hf_hub_download
|
7 |
|
8 |
+
# Download the model from the Hugging Face model hub
|
9 |
+
model_path = hf_hub_download(repo_id="Zeyadd-Mostaffa/cv_GP", filename="xception_model.h5")
|
10 |
+
model = load_model(model_path)
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
# Preprocessing and prediction
|
13 |
def predict(image):
|
14 |
+
# Resize image to expected shape (299x299x3 for Xception)
|
15 |
+
image = image.resize((299, 299))
|
16 |
+
image = img_to_array(image)
|
17 |
+
image = np.expand_dims(image, axis=0)
|
18 |
+
image = image / 255.0 # Normalize
|
19 |
+
|
20 |
+
prob = model.predict(image)[0][0]
|
21 |
+
label = "Fake" if prob > 0.5 else "Real"
|
22 |
+
confidence = round(float(prob if prob > 0.5 else 1 - prob), 3)
|
23 |
+
return f"{label} ({confidence})"
|
24 |
|
25 |
+
# Gradio UI
|
26 |
+
iface = gr.Interface(
|
27 |
fn=predict,
|
28 |
inputs=gr.Image(type="pil"),
|
29 |
+
outputs=gr.Text(),
|
30 |
title="Deepfake Detection (Xception Model)"
|
31 |
)
|
32 |
|
33 |
+
iface.launch()
|
34 |
+
|
35 |
|