File size: 1,123 Bytes
01c8d2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import tensorflow as tf
import numpy as np
from tensorflow.keras.preprocessing import image
import os


model = tf.keras.models.load_model('my_cnn_model_7.h5')  


def predict_image(img):
   
    img = img.resize((64, 64))  
    img_array = np.array(img)  
    img_array = np.expand_dims(img_array, axis=0) 
    img_array = img_array / 255.0  
    
    
    predictions = model.predict(img_array)
    
    prediction_label = (predictions > 0.5).astype("int32")
    
    return prediction_label[0][0]  

# Streamlit UI
st.title("Image Classifier: Real vs Fake")
st.write("Upload an image to classify it as 'Real' or 'Fake'.")


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

if uploaded_file is not None:
    
    img = image.open(uploaded_file)
    st.image(img, caption="Uploaded Image.", use_column_width=True)
    
    
    if st.button('Classify'):
        prediction = predict_image(img)
        if prediction == 1:
            st.write("Prediction: The given image is **Real**")
        else:
            st.write("Prediction: The given image is **Fake**")