Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import numpy as np
|
3 |
+
import gradio as gr
|
4 |
+
from tensorflow.keras.utils import img_to_array
|
5 |
+
from tensorflow.keras.models import load_model
|
6 |
+
import os
|
7 |
+
|
8 |
+
model = load_model(r'deepfake_detection_model.h5')
|
9 |
+
|
10 |
+
def predict_image(img):
|
11 |
+
|
12 |
+
x = img_to_array(img)
|
13 |
+
|
14 |
+
x = cv2.resize(x, (256, 256), interpolation=cv2.INTER_AREA)
|
15 |
+
|
16 |
+
x /= 255.0
|
17 |
+
|
18 |
+
x = np.expand_dims(x, axis=0)
|
19 |
+
|
20 |
+
prediction = np.argmax(model.predict(x), axis=1)
|
21 |
+
|
22 |
+
if prediction == 0:
|
23 |
+
return 'Fake Image'
|
24 |
+
else:
|
25 |
+
return 'Real Image'
|
26 |
+
|
27 |
+
|
28 |
+
# Define the Gradio Interface with the desired title and description
|
29 |
+
|
30 |
+
description_html = """
|
31 |
+
<p>Upload a face image to check if it's real or morphed with deepfake</p>
|
32 |
+
"""
|
33 |
+
|
34 |
+
# Define example images and their true labels for users to choose from
|
35 |
+
|
36 |
+
custom_css = """
|
37 |
+
div {background-color: whitesmoke;}
|
38 |
+
"""
|
39 |
+
|
40 |
+
gr.Interface(
|
41 |
+
fn=predict_image,
|
42 |
+
inputs='image',
|
43 |
+
outputs='text',
|
44 |
+
title="Deepfake Image Detection",
|
45 |
+
description=description_html,
|
46 |
+
allow_flagging='never'
|
47 |
+
).launch()
|