File size: 868 Bytes
b9089fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# 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']}")