Spaces:
Sleeping
Sleeping
ready to test
Browse files- app.py +52 -0
- best_model.h5 +3 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from tensorflow.keras.models import load_model
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
import cv2
|
6 |
+
from tensorflow.keras.preprocessing.image import img_to_array, load_img
|
7 |
+
|
8 |
+
|
9 |
+
@st.cache_data()
|
10 |
+
def load():
|
11 |
+
model_path = "best_model.h5"
|
12 |
+
model = load_model(model_path, compile=False)
|
13 |
+
return model
|
14 |
+
|
15 |
+
|
16 |
+
# chargement du model
|
17 |
+
model = load()
|
18 |
+
|
19 |
+
|
20 |
+
def predict(upload):
|
21 |
+
img = Image.open(upload)
|
22 |
+
img = np.asarray(img)
|
23 |
+
img_resize = cv2.resize(img, (224, 224))
|
24 |
+
img_resize = np.expand_dims(img_resize, axis=0)
|
25 |
+
pred = model.predict(img_resize)
|
26 |
+
rec = pred[0][0]
|
27 |
+
return rec
|
28 |
+
|
29 |
+
def draw():
|
30 |
+
#rectangle sur la prediction
|
31 |
+
img = cv2.imread(upload)
|
32 |
+
img = cv2.resize(img, (224, 224))
|
33 |
+
img = cv2.rectangle(img, (0, 0), (224, 224), (0, 255, 0), 3)
|
34 |
+
cv2.imwrite('output.png', img)
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
st.title("Poubelle Intelligente")
|
39 |
+
|
40 |
+
upload = st.file_uploader("Charger Image", type=["pnj", "jpeg", "jpg"])
|
41 |
+
|
42 |
+
c1, c2 = st.columns(2)
|
43 |
+
|
44 |
+
if upload:
|
45 |
+
rec = predict(upload)
|
46 |
+
prob_rec = predict(upload) * 100
|
47 |
+
prob_org = (1 - rec) * 100
|
48 |
+
c1.image(Image.open(upload))
|
49 |
+
if prob_rec > 50:
|
50 |
+
c2.write(f"Je suis certains à {prob_rec:.2f} % que ceci est recyclable")
|
51 |
+
else:
|
52 |
+
c2.write(f"Je suis certains à {prob_org:.2f} % que ceci ne soit pas recyclable")
|
best_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3afdac06a661337838146779626c57c39ee81a70d7641ac5acf3870b01a178b2
|
3 |
+
size 20850712
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
tensorflow
|
3 |
+
numpy
|
4 |
+
opencv-python
|
5 |
+
Pillow
|