Senasu commited on
Commit
71bf920
·
verified ·
1 Parent(s): 7950699

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +89 -0
  2. cnn_model.h5 +3 -0
  3. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from tensorflow.keras.models import load_model
3
+ from PIL import Image
4
+ import numpy as np
5
+
6
+ # Load the model
7
+ model = load_model('cnn_model.h5', compile=False)
8
+
9
+ # Function to process the uploaded image
10
+ def process_image(img):
11
+ img = img.resize((64, 64))
12
+ img = np.array(img)
13
+ img = img / 255.0
14
+ img = np.expand_dims(img, axis=0)
15
+ return img
16
+
17
+ # Custom CSS for better design
18
+ st.markdown("""
19
+ <style>
20
+ .main {
21
+ background-color: #f0f4f7;
22
+ padding: 2rem;
23
+ border-radius: 10px;
24
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
25
+ }
26
+ h1 {
27
+ color: #4caf50;
28
+ font-size: 36px;
29
+ font-weight: bold;
30
+ text-align: center;
31
+ }
32
+ .description {
33
+ font-size: 18px;
34
+ color: #555;
35
+ text-align: center;
36
+ margin-bottom: 2rem;
37
+ }
38
+ .stButton>button {
39
+ background-color: #4caf50;
40
+ color: white;
41
+ font-size: 18px;
42
+ border-radius: 5px;
43
+ padding: 10px 20px;
44
+ margin-top: 20px;
45
+ border: none;
46
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
47
+ }
48
+ .stButton>button:hover {
49
+ background-color: #45a049;
50
+ }
51
+ </style>
52
+ """, unsafe_allow_html=True)
53
+
54
+ # Title of the application
55
+ st.title('Glass Detection from Image 📸')
56
+
57
+ # Brief description
58
+ st.markdown('<p class="description">Upload a photo, and the model will predict whether there is a glass or not.</p>', unsafe_allow_html=True)
59
+
60
+ # File uploader for the user to upload an image
61
+ file = st.file_uploader('Select an image (jpg, jpeg, png)', type=['jpg', 'jpeg', 'png'])
62
+
63
+ if file is not None:
64
+ # Displaying the uploaded image
65
+ img = Image.open(file)
66
+ st.image(img, caption='Uploaded Image', use_column_width=True)
67
+
68
+ # Processing the image
69
+ image = process_image(img)
70
+ prediction = model.predict(image)
71
+
72
+ # Get the predicted class index
73
+ predicted_class = np.argmax(prediction, axis=-1)
74
+
75
+ # Displaying prediction result
76
+ st.subheader("Prediction Result:")
77
+
78
+ if predicted_class == 1:
79
+ prediction_text = '✅ There is a glass'
80
+ else:
81
+ prediction_text = '❌ There is no a glass'
82
+
83
+ st.write(prediction_text)
84
+
85
+ else:
86
+ st.write("Please upload an image to get started.")
87
+
88
+ # Footer
89
+ st.markdown("<p style='text-align: center; font-size: 12px; color: #888;'>Built with 💚 by Senasu Demir</p>", unsafe_allow_html=True)
cnn_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ceb8653b7e4936594513b43be66d4c155d8d1502e5fd2ffe7c22185d5a02ba48
3
+ size 134058560
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ tensorflow
3
+ Pillow