jdesai05 commited on
Commit
7555ff8
·
verified ·
1 Parent(s): 7f578c0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+ from PIL import Image
4
+
5
+ # Define the pipeline
6
+ @st.cache_resource
7
+ def load_pipeline():
8
+ return pipeline("image-classification", model="yangy50/garbage-classification")
9
+
10
+ pipe = load_pipeline()
11
+
12
+ # Streamlit UI
13
+ st.title("Garbage Classification App")
14
+ st.write("Upload an image to classify it as a type of garbage.")
15
+
16
+ # File uploader
17
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
18
+
19
+ if uploaded_file is not None:
20
+ # Load image
21
+ image = Image.open(uploaded_file)
22
+
23
+ # Display image
24
+ st.image(image, caption="Uploaded Image", use_column_width=True)
25
+
26
+ # Run inference
27
+ results = pipe(image)
28
+
29
+ # Get top prediction
30
+ top_prediction = max(results, key=lambda x: x["score"])
31
+
32
+ # Display result
33
+ st.write(f"**Predicted Class:** {top_prediction['label']}")
34
+ st.write(f"**Confidence:** {top_prediction['score']:.2f}")