import streamlit as st from transformers import pipeline, AutoImageProcessor, AutoModelForImageClassification from PIL import Image import requests # Load the model and processor st.title("Food Image Classification with Hugging Face") st.write("Upload an image to classify the type of food!") # Load the model @st.cache_resource def load_pipeline(): return pipeline("image-classification", model="Shresthadev403/food-image-classification") pipe = load_pipeline() # Upload image uploaded_file = st.file_uploader("Choose a food image...", type=["jpg", "png", "jpeg"]) if uploaded_file is not None: # Display the uploaded image image = Image.open(uploaded_file) st.image(image, caption="Uploaded Image", use_column_width=True) st.write("Classifying...") # Make predictions predictions = pipe(image) # Display top prediction st.subheader("Top Prediction") st.write(f"**{predictions[0]['label']}** with confidence {predictions[0]['score']:.2f}") # Display other predictions st.subheader("Other Predictions") for pred in predictions[1:]: st.write(f"{pred['label']}: {pred['score']:.2f}")