Spaces:
Build error
Build error
Download app.py from FerdinandPyCode/classification_dechets: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/spaces/FerdinandPyCode/classification_dechets/resolve/46381e33bb7a75ac7b159bcbdf5cbb60015e8238/app.py
- Command line
-
hf download hf://spaces/FerdinandPyCode/classification_dechets@46381e33bb7a75ac7b159bcbdf5cbb60015e8238/app.py
-
curl -L -o app.py https://huggingface.co/spaces/FerdinandPyCode/classification_dechets/resolve/46381e33bb7a75ac7b159bcbdf5cbb60015e8238/app.py
1.16 kB
| import streamlit as st | |
| from tensorflow.keras.models import load_model | |
| import numpy as np | |
| from PIL import Image | |
| import cv2 | |
| from tensorflow.keras.preprocessing.image import img_to_array, load_img | |
| def load(): | |
| model_path = "best_model.h5" | |
| model = load_model(model_path, compile=False) | |
| return model | |
| # Chargement du model | |
| model = load() | |
| def predict(upload): | |
| img = Image.open(upload) | |
| img = np.asarray(img) | |
| img_resize = cv2.resize(img, (224, 224)) | |
| img_resize = np.expand_dims(img_resize, axis=0) | |
| pred = model.predict(img_resize) | |
| rec = pred[0][0] | |
| return rec | |
| st.title("Poubelle Intelligente") | |
| upload = st.file_uploader("Chargez l'image de votre objet", | |
| type=['png', 'jpeg', 'jpg']) | |
| c1, c2 = st.columns(2) | |
| if upload: | |
| rec = predict(upload) | |
| prob_recyclable = rec * 100 | |
| prob_organic = (1-rec)*100 | |
| c1.image(Image.open(upload)) | |
| if prob_recyclable > 50: | |
| c2.write(f"Je suis certain à {prob_recyclable:.2f} % que l'objet est recyclable") | |
| else: | |
| c2.write(f"Je suis certain à {prob_organic:.2f} % que l'objet n'est pas recyclable") | |