| import streamlit as st |
| import tensorflow as tf |
| from tensorflow.keras.preprocessing import image |
| import numpy as np |
| from PIL import Image |
|
|
| |
| model = tf.keras.models.load_model('deepfake_detection.h5') |
|
|
| |
| def load_and_preprocess_image(uploaded_image): |
| img = Image.open(uploaded_image) |
| img = img.resize((150, 150)) |
| img_array = image.img_to_array(img) |
| img_array = np.expand_dims(img_array, axis=0) |
| img_array = img_array / 255.0 |
| return img_array |
|
|
| |
| def predict_image(uploaded_image): |
| img_array = load_and_preprocess_image(uploaded_image) |
| prediction = model.predict(img_array) |
| |
| if prediction < 0.5: |
| return "Fake" |
| else: |
| return "Real" |
|
|
| |
| st.title("Deepfake Image Classification") |
| st.write("Upload an image and the model will predict whether it's Real or Fake.") |
|
|
| |
| uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg"]) |
|
|
| |
| if uploaded_image is not None: |
| st.image(uploaded_image, caption="Uploaded Image", use_column_width=True) |
| st.write("") |
| |
| if st.button("Predict"): |
| result = predict_image(uploaded_image) |
| if result == "Fake": |
| st.write("The image is **<span style='color:red;'>Fake</span>**", unsafe_allow_html=True) |
| else: |
| st.write("The image is **<span style='color:cyan;'>Real</span>**", unsafe_allow_html=True) |
|
|