xujinheng666 commited on
Commit
8295fb5
·
verified ·
1 Parent(s): 659796c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+ from PIL import Image
4
+
5
+ # Load the classifier model
6
+ @st.cache_resource
7
+ def load_classifier():
8
+ return pipeline("image-classification", model="nateraw/vit-age-classifier")
9
+
10
+ classifier = load_classifier()
11
+
12
+ # Streamlit UI
13
+ st.title("Age Classifier App 🧑👵")
14
+ st.write("Upload an image to predict the age category.")
15
+
16
+ # Upload an image
17
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
18
+
19
+ if uploaded_file is not None:
20
+ # Load and display the image
21
+ image = Image.open(uploaded_file).convert("RGB")
22
+ st.image(image, caption="Uploaded Image", use_column_width=True)
23
+
24
+ # Classify the age
25
+ st.write("Classifying...")
26
+ results = classifier(image)
27
+
28
+ # Display results
29
+ st.subheader("Results:")
30
+ for result in results:
31
+ st.write(f"**{result['label']}** - Score: {result['score']:.4f}")