VINAYAK MODI
commited on
Commit
•
cacd2bb
1
Parent(s):
7f41876
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,51 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import streamlit as st
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
import tensorflow as tf
|
6 |
+
|
7 |
+
# Load your deep fake detection model
|
8 |
+
@st.cache(allow_output_mutation=True)
|
9 |
+
def load_model():
|
10 |
+
model = tf.keras.models.load_model("models/vm24bho/net_dfm_myimg")
|
11 |
+
return model
|
12 |
+
|
13 |
+
# Function to preprocess the image
|
14 |
+
def preprocess_image(image):
|
15 |
+
image = np.array(image)
|
16 |
+
# Add your preprocessing steps here, like resizing, normalization, etc.
|
17 |
+
return image
|
18 |
+
|
19 |
+
def main():
|
20 |
+
st.title("Deep Fake Image Detection")
|
21 |
+
st.markdown("""
|
22 |
+
Detect whether an image has been manipulated or synthetically generated using our state-of-the-art deep fake detection model.
|
23 |
+
### How to Use
|
24 |
+
1. Upload an image by clicking the "Browse Files" button below.
|
25 |
+
2. Our model will analyze the image and determine if it's real or fake.
|
26 |
+
3. The result will be displayed, along with a confidence score.
|
27 |
+
Give it a try! 📷
|
28 |
+
""")
|
29 |
+
|
30 |
+
uploaded_image = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
|
31 |
+
|
32 |
+
if uploaded_image is not None:
|
33 |
+
model = load_model()
|
34 |
+
image = Image.open(uploaded_image)
|
35 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
36 |
+
|
37 |
+
# Preprocess the image
|
38 |
+
processed_image = preprocess_image(image)
|
39 |
+
|
40 |
+
# Make prediction
|
41 |
+
prediction = model.predict(np.expand_dims(processed_image, axis=0))[0][0]
|
42 |
+
|
43 |
+
if prediction > 0.5:
|
44 |
+
st.error("This image is predicted to be a deep fake.")
|
45 |
+
else:
|
46 |
+
st.success("This image is predicted to be real.")
|
47 |
+
|
48 |
+
st.write(f"Confidence Score: {prediction:.2f}")
|
49 |
+
|
50 |
+
if __name__ == "__main__":
|
51 |
+
main()
|