File size: 1,064 Bytes
e242f20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import torch

#function part

def classify_image(image_path):
    # Load the pre-trained image classification model
    classifier = pipeline("image-classification", model="nateraw/vit-age-classifier")
    image = Image.open(image_path)
    predictions = classifier(image)
    return predictions

st.set_page_config(page_title="Age Classifier", page_icon="📷")
st.header("Image Age Classification")

uploaded_file = st.file_uploader("Upload an Image...", type=["png", "jpg", "jpeg"])

if uploaded_file is not None:
    image = Image.open(uploaded_file)
    st.image(image, caption="Uploaded Image", use_column_width=True)
    
    # Perform image classification
    st.text('Classifying image...')
    predictions = classify_image(uploaded_file)
    
    # Display the top prediction
    if predictions:
        top_prediction = predictions[0]
        st.write(f"**Predicted Age Group:** {top_prediction['label']}")
        st.write(f"**Confidence:** {top_prediction['score']:.2f}")