yiw commited on
Commit
87eca67
·
1 Parent(s): 7312dc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -28
app.py CHANGED
@@ -10,35 +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
- if uploaded_file!=None:
15
-
16
- img=Image.open(uploaded_file)
17
-
18
- extractor = AutoFeatureExtractor.from_pretrained("yangy50/garbage-classification")
19
- model = AutoModelForImageClassification.from_pretrained("yangy50/garbage-classification")
20
-
21
- inputs = extractor(img,return_tensors="pt")
22
- outputs = model(**inputs)
23
- label_num=outputs.logits.softmax(1).argmax(1)
24
- label_num=label_num.item()
25
-
26
- st.write("The prediction class is:")
27
-
28
- if label_num==0:
29
- st.write("cardboard")
30
- elif label_num==1:
31
- st.write("glass")
32
- elif label_num==2:
33
- st.write("metal")
34
- elif label_num==3:
35
- st.write("paper")
36
- elif label_num==4:
37
- st.write("plastic")
38
- else:
39
- st.write("trash")
40
-
41
- st.image(img)
42
 
43
  if __name__ == "__main__":
44
  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()