Upload 3 files
Browse files- app.py +46 -0
- deepfake_detection.h5 +3 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
from tensorflow.keras.preprocessing import image
|
| 4 |
+
import numpy as np
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
# Load the trained model
|
| 8 |
+
model = tf.keras.models.load_model('deepfake_detection.h5')
|
| 9 |
+
|
| 10 |
+
# Function to load and preprocess the image
|
| 11 |
+
def load_and_preprocess_image(uploaded_image):
|
| 12 |
+
img = Image.open(uploaded_image)
|
| 13 |
+
img = img.resize((150, 150)) # Resize image to match the input size expected by the model
|
| 14 |
+
img_array = image.img_to_array(img) # Convert the image to a numpy array
|
| 15 |
+
img_array = np.expand_dims(img_array, axis=0) # Expand dimensions to match the input shape (1, 150, 150, 3)
|
| 16 |
+
img_array = img_array / 255.0 # Rescale the image array
|
| 17 |
+
return img_array
|
| 18 |
+
|
| 19 |
+
# Function to predict whether the image is real or fake
|
| 20 |
+
def predict_image(uploaded_image):
|
| 21 |
+
img_array = load_and_preprocess_image(uploaded_image)
|
| 22 |
+
prediction = model.predict(img_array)
|
| 23 |
+
|
| 24 |
+
if prediction < 0.5:
|
| 25 |
+
return "Fake"
|
| 26 |
+
else:
|
| 27 |
+
return "Real"
|
| 28 |
+
|
| 29 |
+
# Streamlit app layout
|
| 30 |
+
st.title("Deepfake Image Classification")
|
| 31 |
+
st.write("Upload an image and the model will predict whether it's Real or Fake.")
|
| 32 |
+
|
| 33 |
+
# Image uploader
|
| 34 |
+
uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg"])
|
| 35 |
+
|
| 36 |
+
# Prediction button
|
| 37 |
+
if uploaded_image is not None:
|
| 38 |
+
st.image(uploaded_image, caption="Uploaded Image", use_column_width=True)
|
| 39 |
+
st.write("")
|
| 40 |
+
|
| 41 |
+
if st.button("Predict"):
|
| 42 |
+
result = predict_image(uploaded_image)
|
| 43 |
+
if result == "Fake":
|
| 44 |
+
st.write("The image is **<span style='color:red;'>Fake</span>**", unsafe_allow_html=True)
|
| 45 |
+
else:
|
| 46 |
+
st.write("The image is **<span style='color:blue;'>Real</span>**", unsafe_allow_html=True)
|
deepfake_detection.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:db4a19bec4dfe407ac645770ad9bee77a6d911add57289bec0206b8ad501ff8c
|
| 3 |
+
size 228464648
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
pillow
|
| 3 |
+
numpy
|
| 4 |
+
tensorflow
|