CR7CAD commited on
Commit
d4230ec
·
verified ·
1 Parent(s): c86974f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+ from PIL import Image
4
+ import matplotlib.pyplot as plt
5
+
6
+ # Load the pre-trained model
7
+ age_classifier = pipeline("image-classification", model="nateraw/vit-age-classifier")
8
+
9
+ # Function to classify age from an image
10
+ def classify_age(image):
11
+ result = age_classifier(image)
12
+ predicted_age = result[0]['label']
13
+ confidence = result[0]['score']
14
+ return predicted_age, confidence
15
+
16
+ # Streamlit UI
17
+ st.title("Age Classification App")
18
+ st.write("Upload an image to classify the person's age.")
19
+
20
+ # File uploader
21
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
22
+
23
+ # Process the uploaded image
24
+ if uploaded_file is not None:
25
+ image = Image.open(uploaded_file).convert("RGB")
26
+
27
+ # Display uploaded image
28
+ st.image(image, caption="Uploaded Image", use_column_width=True)
29
+
30
+ # Get prediction
31
+ predicted_age, confidence = classify_age(image)
32
+
33
+ # Show results
34
+ st.write(f"### Predicted Age: {predicted_age}")
35
+ st.write(f"**Confidence:** {confidence:.2f}")