Spaces:
Runtime error
Runtime error
yuechen-yang
commited on
Commit
·
6a2d000
1
Parent(s):
683ae67
add None
Browse files
app.py
CHANGED
|
@@ -19,29 +19,32 @@ def main():
|
|
| 19 |
|
| 20 |
st.header("Try it out!")
|
| 21 |
|
| 22 |
-
uploaded_file = st.file_uploader("Upload Files",type=['png','jpeg'])
|
| 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 |
|
|
|
|
| 19 |
|
| 20 |
st.header("Try it out!")
|
| 21 |
|
| 22 |
+
uploaded_file = st.file_uploader("Upload Files",type=['png','jpeg','jpg'])
|
| 23 |
+
|
| 24 |
+
if uploaded_file!=None:
|
| 25 |
+
|
| 26 |
+
img=Image.open(uploaded_file)
|
| 27 |
+
|
| 28 |
+
extractor = AutoFeatureExtractor.from_pretrained("yangy50/garbage-classification")
|
| 29 |
+
model = AutoModelForImageClassification.from_pretrained("yangy50/garbage-classification")
|
| 30 |
+
|
| 31 |
+
inputs = extractor(img,return_tensors="pt")
|
| 32 |
+
outputs = model(**inputs)
|
| 33 |
+
label_num=outputs.logits.softmax(1).argmax(1)
|
| 34 |
+
label_num=label_num.item()
|
| 35 |
+
|
| 36 |
+
if label_num==0:
|
| 37 |
+
st.write("cardboard")
|
| 38 |
+
elif label_num==1:
|
| 39 |
+
st.write("glass")
|
| 40 |
+
elif label_num==2:
|
| 41 |
+
st.write("metal")
|
| 42 |
+
elif label_num==3:
|
| 43 |
+
st.write("paper")
|
| 44 |
+
elif label_num==4:
|
| 45 |
+
st.write("plastic")
|
| 46 |
+
else:
|
| 47 |
+
st.write("trash")
|
| 48 |
|
| 49 |
|
| 50 |
|