adityamajji commited on
Commit
128d535
·
1 Parent(s): ade4c58

Upload 3 files

Browse files
Files changed (3) hide show
  1. Requirements.txt +6 -0
  2. app.py +55 -0
  3. mymodel2.h5 +3 -0
Requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ streamlit
2
+ tensorflow
3
+ keras
4
+ opencv-python
5
+ numpy
6
+ pillow
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ import numpy as np
4
+ from keras.models import load_model
5
+ import tensorflow as tf
6
+
7
+ @st.cache_resource
8
+ def load_model():
9
+ model=tf.keras.models.load_model('mymodel2.h5')
10
+ return model
11
+ with st.spinner('Model is being loaded..'):
12
+ model=load_model()
13
+
14
+ st.write("""
15
+ # AI Image Classification
16
+ """
17
+ )
18
+
19
+ with open('style.css') as f:
20
+ st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
21
+
22
+ file = st.file_uploader('Please upload an image', type=["jpg", "png", "jpeg", "webm"],)
23
+ import cv2
24
+ from PIL import Image, ImageOps
25
+ from tensorflow.keras.models import load_model
26
+ from tensorflow.keras.preprocessing import image
27
+ import numpy as np
28
+ st.set_option('deprecation.showfileUploaderEncoding', False)
29
+ def import_and_predict(image_data, model):
30
+
31
+ size = (224,224)
32
+ image = ImageOps.fit(image_data, size)
33
+ img = np.asarray(image)
34
+ img=img/255
35
+ img=np.expand_dims(img,[0])
36
+
37
+ prediction = model.predict(img)
38
+
39
+ return prediction
40
+ if file is None:
41
+ st.text('Please upload an image file')
42
+ else:
43
+ image = Image.open(file)
44
+ image = image.convert("RGB")
45
+ st.image(image, use_column_width=True)
46
+ try:
47
+ predictions = import_and_predict(image, model)
48
+ score = tf.nn.softmax(predictions[0])
49
+ predictions = np.argmax(predictions, axis = 1)
50
+ if(predictions == 0):
51
+ st.write('<p class = "prediction">The image is most likely an AI Generated Image</p>', unsafe_allow_html=True)
52
+ else:
53
+ st.write('<p class = "prediction">The image is most likely a Real Image</p>', unsafe_allow_html=True)
54
+ except Exception as e:
55
+ st.write(f'An error occurred during prediction')
mymodel2.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fe6442e51cc85095216ff82f56943142876e898904b28dded0320b0253aa924f
3
+ size 59541528