WRX020510's picture
Create app.py
b9089fc verified
raw
history blame contribute delete
868 Bytes
# huggingface运行版本,app.py
import streamlit as st
from transformers import pipeline
from PIL import Image
# Load the age classification pipeline
pipe = pipeline("image-classification", model="nateraw/vit-age-classifier")
def classify_age(image):
"""Classifies the age group of the person in the given image."""
results = pipe(image)
return results
# Streamlit UI
st.title("Age Classification App")
st.write("Upload an image to classify the age group of the person in it.")
uploaded_file = st.file_uploader("Upload an image...", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
image = Image.open(uploaded_file).convert("RGB")
st.image(image, caption="Uploaded Image", use_column_width=True)
st.write("Classifying...")
age_results = classify_age(image)
st.write(f"Predicted Age Range: {age_results[0]['label']}")