File size: 1,588 Bytes
01c8d2e
 
44af2df
874c77e
44af2df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9d656d9
 
44af2df
 
 
 
 
 
 
 
 
 
 
 
7238680
cde2b69
01c8d2e
44af2df
 
 
 
01c8d2e
44af2df
 
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
import streamlit as st
import numpy as np
import tensorflow as tf
from PIL import Image
import cv2

# Load the model
model = tf.keras.models.load_model('cnn_real_fake_4.h5')

# Define a function to preprocess the uploaded image
def preprocess_image(image):
    img_size = (256, 256)
    image = image.resize(img_size)  # Resize image
    image = np.array(image)  # Convert to numpy array
    image = image / 255.0  # Normalize to [0, 1]
    image = np.expand_dims(image, axis=0)  # Add batch dimension
    return image

# Define a function for making predictions
def predict_image(image):
    preprocessed_image = preprocess_image(image)
    prediction = model.predict(preprocessed_image)
    if prediction > 0.5:
        return 'Fake'
    else:
        return 'Real'

# Streamlit app interface
with open("style.css") as f:
      st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
st.title('Real or Fake Image Classifier')

st.write("""
    This app allows you to upload an image and classify it as either Real or Fake.
""")

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

if uploaded_image is not None:
    # Display the uploaded image
    image = Image.open(uploaded_image)
    img_resized = image.resize((100, 100))
    st.image(img_resized, caption='Uploaded Image', use_container_width=False)
    
    # Predict the image
    st.write("")
    st.write("Classifying the image...")
    result = predict_image(image)
    
    # Display the result
    st.write(f"The uploaded image is classified as: **{result}**")