Spaces:
Running
Running
File size: 1,014 Bytes
8295fb5 3d20cd6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import streamlit as st
from transformers import pipeline
from PIL import Image
# Load the classifier model
@st.cache_resource
def load_classifier():
return pipeline("image-classification", model="nateraw/vit-age-classifier")
classifier = load_classifier()
# Streamlit UI
st.title("Age Classifier App 🧑👵")
st.write("Upload an image to predict the age category.")
# Upload an image
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
if uploaded_file is not None:
# Load and display the image
image = Image.open(uploaded_file).convert("RGB")
st.image(image, caption="Uploaded Image", use_column_width=True)
# Classify the age
st.write("Classifying...")
results = classifier(image)
# Get the label with the highest score
if results:
best_result = max(results, key=lambda x: x["score"])
st.subheader("Predicted Age Category:")
st.write(f"🟢 **{best_result['label']}** (Confidence: {best_result['score']:.4f})")
|