WRX020510 commited on
Commit
b9089fc
·
verified ·
1 Parent(s): 7e2fe85

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # huggingface运行版本,app.py
2
+
3
+ import streamlit as st
4
+ from transformers import pipeline
5
+ from PIL import Image
6
+
7
+ # Load the age classification pipeline
8
+ pipe = pipeline("image-classification", model="nateraw/vit-age-classifier")
9
+
10
+ def classify_age(image):
11
+ """Classifies the age group of the person in the given image."""
12
+ results = pipe(image)
13
+ return results
14
+
15
+ # Streamlit UI
16
+ st.title("Age Classification App")
17
+ st.write("Upload an image to classify the age group of the person in it.")
18
+
19
+ uploaded_file = st.file_uploader("Upload an image...", type=["jpg", "jpeg", "png"])
20
+
21
+ if uploaded_file is not None:
22
+ image = Image.open(uploaded_file).convert("RGB")
23
+ st.image(image, caption="Uploaded Image", use_column_width=True)
24
+ st.write("Classifying...")
25
+ age_results = classify_age(image)
26
+ st.write(f"Predicted Age Range: {age_results[0]['label']}")