Upload 3 files
Browse files- .gitattributes +1 -0
- app.py +45 -0
- model.keras +3 -0
- requirement.txt +7 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
model.keras filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
import tensorflow as tf
|
4 |
+
import numpy as np
|
5 |
+
from keras.preprocessing.image import img_to_array
|
6 |
+
import os
|
7 |
+
|
8 |
+
|
9 |
+
@st.cache_resource
|
10 |
+
def load_model():
|
11 |
+
model_path = "model.keras" # Update with the absolute file path
|
12 |
+
return tf.keras.models.load_model(model_path)
|
13 |
+
|
14 |
+
model = load_model()
|
15 |
+
|
16 |
+
def prepare_image(img):
|
17 |
+
img = img.resize((220, 220))
|
18 |
+
img_array = img_to_array(img)
|
19 |
+
img_array = np.expand_dims(img_array, axis=0)
|
20 |
+
|
21 |
+
prediction = model.predict(img_array)
|
22 |
+
predicted_class = "Smoking" if prediction > 0.5 else "Not Smoking"
|
23 |
+
|
24 |
+
return predicted_class, prediction[0]
|
25 |
+
|
26 |
+
def run():
|
27 |
+
st.title("Smoking or Not Smoking Detection")
|
28 |
+
img_file = st.file_uploader("Choose an Image", type=["jpg", "png"])
|
29 |
+
|
30 |
+
if img_file is not None:
|
31 |
+
img = Image.open(img_file).resize((250, 250))
|
32 |
+
st.image(img, use_column_width=False)
|
33 |
+
|
34 |
+
# Create the directory if it doesn't exist
|
35 |
+
upload_dir = './upload_images/'
|
36 |
+
os.makedirs(upload_dir, exist_ok=True)
|
37 |
+
|
38 |
+
save_image_path = os.path.join(upload_dir, img_file.name)
|
39 |
+
with open(save_image_path, "wb") as f:
|
40 |
+
f.write(img_file.getbuffer())
|
41 |
+
|
42 |
+
predicted_class, score = prepare_image(img)
|
43 |
+
st.success(f"**Predicted : {predicted_class}, Score: {score}**")
|
44 |
+
|
45 |
+
run()
|
model.keras
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3fb76f07b54d985b3898621c5c782311d50aac3849f00ca79f55c325eabca10a
|
3 |
+
size 402347000
|
requirement.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
requests==2.29.0
|
2 |
+
streamlit
|
3 |
+
numpy
|
4 |
+
Pillow
|
5 |
+
flask
|
6 |
+
keras
|
7 |
+
tensorflow
|