Emmawang commited on
Commit
872b7ea
1 Parent(s): e7951d1

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ import numpy as np
4
+ import tensorflow as tf
5
+ from huggingface_hub import from_pretrained_keras
6
+
7
+ model = from_pretrained_keras('Emmawang/mobilenet_v2_fake_image_detection')
8
+
9
+ # Define the Streamlit app
10
+ def main():
11
+ st.title("Fake Image Detection")
12
+ st.write("This is a demo of a fake image detection app using a MobileNetV2 model trained on the Fake Image Detection dataset.")
13
+ st.write("Upload an image to see if it's fake or not.")
14
+ st.write("")
15
+
16
+ uploaded_file = st.file_uploader("Choose an image...", type="png")
17
+ if uploaded_file is not None:
18
+
19
+ img = Image.open(uploaded_file).resize([128, 128])
20
+ img = np.array(img).astype(np.float32)
21
+ img = img/255
22
+ img = img.reshape(-1, 128, 128, 3)
23
+ result = get_prediction(img, model)
24
+ if result > 0.5:
25
+ st.write("This image is fake.")
26
+ else:
27
+ st.write("This image is real.")
28
+
29
+
30
+ def get_prediction(image, model):
31
+ prediction = model.predict(image)
32
+ return np.argmax(prediction)
33
+
34
+ if __name__ == '__main__':
35
+ main()
36
+