|
|
import streamlit as st |
|
|
from transformers import pipeline |
|
|
from PIL import Image |
|
|
import io |
|
|
|
|
|
|
|
|
classifier = pipeline("image-classification", model="google/vit-base-patch16-224") |
|
|
|
|
|
|
|
|
st.title("Image Classifier with Hugging Face 🤗") |
|
|
st.write("Upload an image, and the model will predict its content!") |
|
|
|
|
|
|
|
|
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"]) |
|
|
|
|
|
if uploaded_file is not None: |
|
|
|
|
|
image = Image.open(uploaded_file) |
|
|
st.image(image, caption="Uploaded Image", use_column_width=True) |
|
|
|
|
|
|
|
|
st.write("Classifying...") |
|
|
results = classifier(image) |
|
|
|
|
|
|
|
|
for result in results: |
|
|
st.write(f"**{result['label']}**: {result['score']:.4f}") |
|
|
|