Spaces:
Sleeping
Sleeping
File size: 2,351 Bytes
fa84113 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
"""
Streamlit app
"""
import sys
import streamlit as st
from constants import (CLAS_FILEPATH, CLAS_THRESHOLD, CLASSES, DET_FILEPATH,
DET_NAME, DET_THRESHOLD, DEVICE, OUTPUT_IMG_FILEPATH)
sys.path.append("./efficientdet")
from PIL import Image
from efficientdet.efficientdet import plot_results
from trash_detector import detect_trash
def initial_config():
"""
Initial configuration of streamlit page
"""
st.set_page_config(
page_title="Waste Classifier",
page_icon="♻️",
)
def render():
"""
Render the streamlit app
"""
st.title("Waste classifier")
st.markdown("""Classify your waste into different classes""")
# Image loader and button
uploaded_file = st.file_uploader(
"Upload image with trash", type=["jpg", "jpeg", "png", "gif", "bmp"]
)
classify_button = st.button("Classify trash")
if classify_button:
if not uploaded_file:
st.error("Upload an image")
else:
# Create two columns
col1, col2 = st.columns(2)
# Column 1: Uploaded image
with col1:
st.write("Uploaded image")
st.image(
uploaded_file, caption="Uploaded Image.", use_column_width=True
)
# Column 2: Classified image
with col2:
with st.spinner(text="Classifying the trash..."):
img = Image.open(uploaded_file).convert("RGB")
cls_prob, bboxes_final = detect_trash(
img,
DET_NAME,
DET_FILEPATH,
CLAS_FILEPATH,
DEVICE,
DET_THRESHOLD,
CLAS_THRESHOLD,
)
# plot and save demo image
plot_results(
img, cls_prob, bboxes_final, CLASSES, OUTPUT_IMG_FILEPATH
)
output_img = Image.open(OUTPUT_IMG_FILEPATH)
st.write("Classified image")
st.image(
output_img, caption="Classified Image.", use_column_width=True
)
if __name__ == "__main__":
initial_config()
render()
|