File size: 1,203 Bytes
4dad362
8ac1284
 
4dad362
8ac1284
4dad362
8ac1284
 
4dad362
8ac1284
4dad362
8ac1284
 
 
 
42acb46
8ac1284
 
4dad362
8ac1284
 
 
1e756f0
8ac1284
4dad362
8ac1284
4dad362
 
 
 
 
 
 
 
8ac1284
4dad362
 
8ac1284
 
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 gradio as gr
import cv2
import numpy as np
from tensorflow.keras.models import load_model
from tensorflow.keras.utils import img_to_array

# Load the pre-trained model
model = load_model('deepfake_detection_mobilenet_model.h5')

# Define the function for prediction
def predict_image(img):
    # Resize and preprocess the input image
    x = cv2.resize(img, (224, 224))
    x = img_to_array(x) / 255.0  # Normalize the image
    x = np.expand_dims(x, axis=0)  # Add batch dimension
    
    # Predict with the model
    prediction = (model.predict(x) > 0.5).astype("int32")[0][0]
    
    # Return result based on the prediction
    if prediction == 1:
        return "Fake Image"
    else:
        return "Real Image"

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

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

# Create the Gradio app interface
gr.Interface(
    fn=predict_image,
    inputs=gr.Image(type="numpy", label="Upload Face Image"),
    outputs=gr.Textbox(label="Prediction"),
    title="Deepfake Image Detection",
    description=description_html,
    allow_flagging='never'
).launch()