Update app.py
Browse files
app.py
CHANGED
@@ -10,36 +10,36 @@ def main():
|
|
10 |
|
11 |
with st.form("text_field"):
|
12 |
uploaded_file = st.file_uploader("Upload Files",type=['png','jpeg','jpg'])
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
img=Image.open(uploaded_file)
|
18 |
-
|
19 |
-
extractor = AutoFeatureExtractor.from_pretrained("yangy50/garbage-classification")
|
20 |
-
model = AutoModelForImageClassification.from_pretrained("yangy50/garbage-classification")
|
21 |
-
|
22 |
-
inputs = extractor(img,return_tensors="pt")
|
23 |
-
outputs = model(**inputs)
|
24 |
-
label_num=outputs.logits.softmax(1).argmax(1)
|
25 |
-
label_num=label_num.item()
|
26 |
-
|
27 |
-
st.write("The prediction class is:")
|
28 |
-
|
29 |
-
if label_num==0:
|
30 |
-
st.write("cardboard")
|
31 |
-
elif label_num==1:
|
32 |
-
st.write("glass")
|
33 |
-
elif label_num==2:
|
34 |
-
st.write("metal")
|
35 |
-
elif label_num==3:
|
36 |
-
st.write("paper")
|
37 |
-
elif label_num==4:
|
38 |
-
st.write("plastic")
|
39 |
-
else:
|
40 |
-
st.write("trash")
|
41 |
-
|
42 |
-
st.image(img)
|
43 |
-
|
44 |
if __name__ == "__main__":
|
45 |
main()
|
|
|
10 |
|
11 |
with st.form("text_field"):
|
12 |
uploaded_file = st.file_uploader("Upload Files",type=['png','jpeg','jpg'])
|
13 |
+
clicked = st.form_submit_button("Submit")
|
14 |
+
if clicked:
|
15 |
+
if uploaded_file!=None:
|
16 |
+
|
17 |
+
img=Image.open(uploaded_file)
|
18 |
+
|
19 |
+
extractor = AutoFeatureExtractor.from_pretrained("yangy50/garbage-classification")
|
20 |
+
model = AutoModelForImageClassification.from_pretrained("yangy50/garbage-classification")
|
21 |
+
|
22 |
+
inputs = extractor(img,return_tensors="pt")
|
23 |
+
outputs = model(**inputs)
|
24 |
+
label_num=outputs.logits.softmax(1).argmax(1)
|
25 |
+
label_num=label_num.item()
|
26 |
+
|
27 |
+
st.write("The prediction class is:")
|
28 |
+
|
29 |
+
if label_num==0:
|
30 |
+
st.write("cardboard")
|
31 |
+
elif label_num==1:
|
32 |
+
st.write("glass")
|
33 |
+
elif label_num==2:
|
34 |
+
st.write("metal")
|
35 |
+
elif label_num==3:
|
36 |
+
st.write("paper")
|
37 |
+
elif label_num==4:
|
38 |
+
st.write("plastic")
|
39 |
+
else:
|
40 |
+
st.write("trash")
|
41 |
+
|
42 |
+
st.image(img)
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
if __name__ == "__main__":
|
45 |
main()
|