|
|
|
import streamlit as st |
|
from transformers import pipeline |
|
from PIL import Image |
|
|
|
|
|
def classify_age(image_path): |
|
|
|
age_classifier = pipeline("image-classification", model="nateraw/vit-age-classifier") |
|
|
|
result = age_classifier(image_path) |
|
return result |
|
|
|
|
|
st.set_page_config(page_title="Age Classifier", page_icon="👶") |
|
st.header("Age Classification using nateraw/vit-age-classifier") |
|
uploaded_file = st.file_uploader("Upload an image of a person...", type=["jpg", "jpeg", "png"]) |
|
|
|
if uploaded_file is not None: |
|
|
|
with open(uploaded_file.name, "wb") as file: |
|
file.write(uploaded_file.getvalue()) |
|
|
|
|
|
st.image(uploaded_file, caption="Uploaded Image", use_container_width=True) |
|
|
|
|
|
st.text('Classifying age...') |
|
age_result = classify_age(uploaded_file.name) |
|
|
|
|
|
st.write("Age Classification Result:") |
|
for res in age_result: |
|
st.write(f"{res['label']}: {res['score']:.2f}") |