Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,28 @@
|
|
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 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
label = "REAL" if prob >= 0.5 else "FAKE"
|
30 |
-
return {"REAL": 1 - prob, "FAKE": prob}, f"Prediction: {label}"
|
31 |
-
|
32 |
-
# Gradio UI
|
33 |
-
demo = gr.Interface(
|
34 |
-
fn=predict,
|
35 |
-
inputs=gr.Image(type="pil"),
|
36 |
-
outputs=[gr.Label(num_top_classes=2), gr.Text()],
|
37 |
-
title="Deepfake Detection (Xception Model)"
|
38 |
-
)
|
39 |
-
|
40 |
-
demo.launch()
|
|
|
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 |
+
# Load pre-uploaded model
|
7 |
+
model = load_model("xception_model.h5")
|
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 |
+
img = preprocess_image(image)
|
16 |
+
prob = model.predict(img)[0][0]
|
17 |
+
label = "REAL" if prob >= 0.5 else "FAKE"
|
18 |
+
return {"REAL": 1 - prob, "FAKE": prob}, f"Prediction: {label}"
|
19 |
+
|
20 |
+
demo = gr.Interface(
|
21 |
+
fn=predict,
|
22 |
+
inputs=gr.Image(type="pil"),
|
23 |
+
outputs=[gr.Label(num_top_classes=2), gr.Text()],
|
24 |
+
title="Deepfake Detection (Xception Model)"
|
25 |
+
)
|
26 |
+
|
27 |
+
demo.launch()
|
28 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|