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 = """
Upload a face image to check if it's real or morphed with deepfake
""" # Define example images and their true labels for users to choose from 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()