File size: 1,011 Bytes
4dad362
 
 
 
 
 
 
450dd26
4dad362
 
 
42acb46
 
 
4dad362
 
 
 
 
 
 
 
1e756f0
 
4dad362
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42acb46
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
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_mobilenet_model.h5')

def predict_image(img):
    x = img_to_array(img)
    
    # Resize to the expected input size of the model
    x = cv2.resize(x, (224, 224), 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 'Real Image'
    else:
        return 'Fake Image'

# Define the Gradio Interface with the desired title and description

description_html = """
<p>Upload a face image to check if it's real or morphed with deepfake</p>
"""

custom_css = """
div {background-color: whitesmoke;}
"""

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