IsmayilMasimov36 commited on
Commit
fc46783
·
verified ·
1 Parent(s): 05c1a93

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from keras.models import load_model
3
+ import cv2
4
+ import numpy as np
5
+ from keras.preprocessing.image import img_to_array
6
+
7
+ def preprocess_image(img, target_size): # Reuse your function with `img` as input
8
+ image = cv2.resize(img, target_size)
9
+ image = img_to_array(image)
10
+ image = image.astype('float32') / 255.0
11
+ image = np.expand_dims(image, axis=0)
12
+ return image
13
+
14
+ # Load the model (outside the main app loop for efficiency)
15
+ model_path = 'C:\\Users\\Istifadeci\Desktop\\Deepfake_konfrans\\xception_deepfake_image_main.h5'
16
+ model = load_model(model_path)
17
+ target_size = (224, 224) # Your model's input size
18
+
19
+ st.title("Deepfake Detection App")
20
+
21
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
22
+
23
+ if uploaded_file is not None:
24
+ # Convert the file to an OpenCV image
25
+ file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
26
+ opencv_image = cv2.imdecode(file_bytes, 1)
27
+
28
+ # Display the image
29
+ st.image(opencv_image, channels="BGR") # OpenCV uses BGR format
30
+
31
+ # Preprocess the image
32
+ preprocessed_image = preprocess_image(opencv_image, target_size)
33
+
34
+ # Make a prediction
35
+ prediction = model.predict(preprocessed_image)
36
+ if prediction[0] > 0.1:
37
+ st.error("The image is predicted as 'FAKE'")
38
+ else:
39
+ st.success("The image is predicted as 'REAL'")