|
import streamlit as st |
|
import numpy as np |
|
import tensorflow as tf |
|
from PIL import Image |
|
import cv2 |
|
|
|
|
|
model = tf.keras.models.load_model('cnn_real_fake_4.h5') |
|
|
|
|
|
def preprocess_image(image): |
|
img_size = (256, 256) |
|
image = image.resize(img_size) |
|
image = np.array(image) |
|
image = image / 255.0 |
|
image = np.expand_dims(image, axis=0) |
|
return image |
|
|
|
|
|
def predict_image(image): |
|
preprocessed_image = preprocess_image(image) |
|
prediction = model.predict(preprocessed_image) |
|
if prediction > 0.5: |
|
return 'Fake' |
|
else: |
|
return 'Real' |
|
|
|
|
|
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. |
|
""") |
|
|
|
|
|
uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"]) |
|
|
|
if uploaded_image is not None: |
|
|
|
image = Image.open(uploaded_image) |
|
img_resized = image.resize((100, 100)) |
|
st.image(img_resized, caption='Uploaded Image', use_container_width=False) |
|
|
|
|
|
st.write("") |
|
st.write("Classifying the image...") |
|
result = predict_image(image) |
|
|
|
|
|
st.write(f"The uploaded image is classified as: **{result}**") |
|
|