File size: 1,376 Bytes
fc46783
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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):  # Reuse your function with `img` as input
    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

# Load the model (outside the main app loop for efficiency) 
model_path = 'C:\\Users\\Istifadeci\Desktop\\Deepfake_konfrans\\xception_deepfake_image_main.h5'
model = load_model(model_path)
target_size = (224, 224)  # Your model's input size

st.title("Deepfake Detection App")

uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])

if uploaded_file is not None:
    # Convert the file to an OpenCV image
    file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
    opencv_image = cv2.imdecode(file_bytes, 1)

    # Display the image
    st.image(opencv_image, channels="BGR")  # OpenCV uses BGR format

    # Preprocess the image
    preprocessed_image = preprocess_image(opencv_image, target_size)

    # Make a prediction
    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'")