HassanDataSci commited on
Commit
04f475a
·
verified ·
1 Parent(s): a245319

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline, AutoImageProcessor, AutoModelForImageClassification
3
+ from PIL import Image
4
+ import requests
5
+
6
+ # Load the model and processor
7
+ st.title("Food Image Classification with Hugging Face")
8
+ st.write("Upload an image to classify the type of food!")
9
+
10
+ # Load the model
11
+ @st.cache_resource
12
+ def load_pipeline():
13
+ return pipeline("image-classification", model="Shresthadev403/food-image-classification")
14
+
15
+ pipe = load_pipeline()
16
+
17
+ # Upload image
18
+ uploaded_file = st.file_uploader("Choose a food image...", type=["jpg", "png", "jpeg"])
19
+
20
+ if uploaded_file is not None:
21
+ # Display the uploaded image
22
+ image = Image.open(uploaded_file)
23
+ st.image(image, caption="Uploaded Image", use_column_width=True)
24
+ st.write("Classifying...")
25
+
26
+ # Make predictions
27
+ predictions = pipe(image)
28
+
29
+ # Display top prediction
30
+ st.subheader("Top Prediction")
31
+ st.write(f"**{predictions[0]['label']}** with confidence {predictions[0]['score']:.2f}")
32
+
33
+ # Display other predictions
34
+ st.subheader("Other Predictions")
35
+ for pred in predictions[1:]:
36
+ st.write(f"{pred['label']}: {pred['score']:.2f}")