Spaces:
Runtime error
Runtime error
File size: 1,124 Bytes
718e70b |
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 |
import streamlit as st
from PIL import Image
from transformers import pipeline
import numpy as np
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
st.set_page_config(layout='wide',
page_title='Garbage image classification'
)
def main():
st.header("Try it out!")
uploaded_file = st.file_uploader("Upload Files",type=['png','jpeg'])
img=Image.open(uploaded_file)
extractor = AutoFeatureExtractor.from_pretrained("yangy50/garbage-classification")
model = AutoModelForImageClassification.from_pretrained("yangy50/garbage-classification")
inputs = extractor(img,return_tensors="pt")
outputs = model(**inputs)
label_num=outputs.logits.softmax(1).argmax(1)
label_num=label_num.item()
if label_num==0:
st.write("cardboard")
elif label_num==1:
st.write("glass")
elif label_num==2:
st.write("metal")
elif label_num==3:
st.write("paper")
elif label_num==4:
st.write("plastic")
else:
st.write("trash")
if __name__ == '__main__':
main() |