File size: 1,423 Bytes
310647f
 
cd405a5
 
 
 
 
 
 
 
 
80b3f89
310647f
 
cd405a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5c764d5
8b91f63
5c764d5
cd405a5
 
 
80b3f89
 
19c1209
cd405a5
 
90f4b4d
3b63a65
cd405a5
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import cv2
import numpy as np 
import gradio as gr
from tensorflow.keras.utils import img_to_array
from tensorflow.keras.models import load_model
import os

model = load_model(r'deepfake_detection_model.h5')

def predict_image(img):
    
    x = img_to_array(img)

    x = cv2.resize(x, (256, 256), interpolation=cv2.INTER_AREA)
    
    x /= 255.0

    x = np.expand_dims(x, axis=0)

    prediction = np.argmax(model.predict(x), axis=1)
    
    if prediction == 0:
        return 'Fake Image'
    else:
        return 'Real Image'


# Define the Gradio Interface with the desired title and description

description_html = """
<p>This model was trained by Rudolf Enyimba in partial fulfillment of the requirements 
of Solent University for the degree of MSc Artificial Intelligence and Data Science</p>
<p>This model was trained to detect deepfake images.</p>
<p>The model achieved an accuracy of <strong>91%</strong> on the test set.</p>
<p>Upload a face image or pick from the samples below to test model accuracy</p>
"""

# Define example images and their true labels for users to choose from
example_data = ['AI POPE.jpg']
custom_css = """
div {background-color: whitesmoke;}
"""

gr.Interface(
    fn=predict_image,
    inputs='image',
    outputs='text',
    title="Deepfake Image Detection(CNN)",
    description=description_html,
    allow_flagging='never',
    examples=example_data,
    css=custom_css
).launch()