|
import streamlit as st |
|
from keras.models import load_model |
|
import cv2 |
|
import numpy as np |
|
from keras.preprocessing.image import img_to_array |
|
|
|
def preprocess_image(img, target_size): |
|
image = cv2.resize(img, target_size) |
|
image = img_to_array(image) |
|
image = image.astype('float32') / 255.0 |
|
image = np.expand_dims(image, axis=0) |
|
return image |
|
|
|
|
|
model_path = 'C:\\Users\\Istifadeci\Desktop\\Deepfake_konfrans\\xception_deepfake_image_main.h5' |
|
model = load_model(model_path) |
|
target_size = (224, 224) |
|
|
|
st.title("Deepfake Detection App") |
|
|
|
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) |
|
|
|
if uploaded_file is not None: |
|
|
|
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8) |
|
opencv_image = cv2.imdecode(file_bytes, 1) |
|
|
|
|
|
st.image(opencv_image, channels="BGR") |
|
|
|
|
|
preprocessed_image = preprocess_image(opencv_image, target_size) |
|
|
|
|
|
prediction = model.predict(preprocessed_image) |
|
if prediction[0] > 0.1: |
|
st.error("The image is predicted as 'FAKE'") |
|
else: |
|
st.success("The image is predicted as 'REAL'") |
|
|