Spaces:
Runtime error
Runtime error
File size: 1,951 Bytes
abd7b7e a712711 c001150 a712711 c001150 a712711 abd7b7e c001150 abd7b7e a712711 abd7b7e |
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import gradio as gr
import cv2
from mtcnn.mtcnn import MTCNN
import tensorflow as tf
import tensorflow_addons
import numpy as np
import os
import zipfile
local_zip = "FINAL-EFFICIENTNETV2-B0.zip"
zip_ref = zipfile.ZipFile(local_zip, 'r')
zip_ref.extractall('FINAL-EFFICIENTNETV2-B0')
zip_ref.close()
detector = MTCNN()
model = tf.keras.models.load_model("FINAL-EFFICIENTNETV2-B0")
def deepfakespredict(input_img):
face = detector.detect_faces(input_img)
text =""
if len(face) > 0:
x, y, width, height = face[0]['box']
x2, y2 = x + width, y + height
cv2.rectangle(input_img, (x, y), (x2, y2), (0, 255, 0), 2)
face_image = input_img[y:y2, x:x2]
face_image2 = cv2.cvtColor(face_image, cv2.COLOR_BGR2RGB)
face_image3 = cv2.resize(face_image2, (224, 224))
face_image4 = face_image3/255
pred = model.predict(np.expand_dims(face_image4, axis=0))[0]
if pred[1] >= 0.6:
text = "The image is fake."
elif pred[0] >= 0.6:
text = "The image is real."
else:
text = "The image might be real or fake."
# if pred[1] >= 0.5:
# text = "The image is fake."
# else:
# text = "The image is real."
else:
text = "Face is not detected in the image."
return pred, text, input_img
title="EfficientNetV2 Deepfakes Image Detector"
description="This is a demo implementation of EfficientNetV2 Deepfakes Image Detector. To use it, simply upload your image, or click one of the examples to load them."
examples = []
demo = gr.Interface(deepfakespredict,
inputs = ["image"],
outputs=["text","text","image"],
title=title,
description=description,
examples=examples
)
demo.launch() |