Spaces:
Sleeping
Sleeping
Leo Liu commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import requests
|
| 3 |
from io import BytesIO
|
| 4 |
from PIL import Image
|
| 5 |
from transformers import pipeline
|
|
@@ -14,7 +13,7 @@ def classify_age(image: Image.Image):
|
|
| 14 |
Classify the age of a person in an image using the nateraw/vit-age-classifier model.
|
| 15 |
|
| 16 |
Args:
|
| 17 |
-
image (PIL.Image): The image to classify.
|
| 18 |
|
| 19 |
Returns:
|
| 20 |
list: Predictions with labels and corresponding confidence scores.
|
|
@@ -24,41 +23,23 @@ def classify_age(image: Image.Image):
|
|
| 24 |
|
| 25 |
def main():
|
| 26 |
st.title("Age Classification with ViT Age Classifier")
|
| 27 |
-
st.write("
|
| 28 |
-
|
| 29 |
-
# Let the user choose the input method
|
| 30 |
-
input_method = st.radio("Select input method:", ("Image URL", "Upload an Image"))
|
| 31 |
-
|
| 32 |
-
image = None
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
try:
|
| 50 |
-
image = Image.open(uploaded_file).convert("RGB")
|
| 51 |
-
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 52 |
-
except Exception as e:
|
| 53 |
-
st.error(f"Error processing uploaded image: {e}")
|
| 54 |
|
| 55 |
-
if image is not None:
|
| 56 |
-
if st.button("Classify Age"):
|
| 57 |
-
with st.spinner("Classifying..."):
|
| 58 |
-
predictions = classify_age(image)
|
| 59 |
-
st.write("### Classification Results:")
|
| 60 |
-
for pred in predictions:
|
| 61 |
-
st.write(f"**Label:** {pred['label']} | **Confidence:** {pred['score']:.2f}")
|
| 62 |
-
|
| 63 |
if __name__ == "__main__":
|
| 64 |
main()
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
from io import BytesIO
|
| 3 |
from PIL import Image
|
| 4 |
from transformers import pipeline
|
|
|
|
| 13 |
Classify the age of a person in an image using the nateraw/vit-age-classifier model.
|
| 14 |
|
| 15 |
Args:
|
| 16 |
+
image (PIL.Image.Image): The image to classify.
|
| 17 |
|
| 18 |
Returns:
|
| 19 |
list: Predictions with labels and corresponding confidence scores.
|
|
|
|
| 23 |
|
| 24 |
def main():
|
| 25 |
st.title("Age Classification with ViT Age Classifier")
|
| 26 |
+
st.write("Upload an image to predict the age category using the `nateraw/vit-age-classifier` model.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
# Upload an image
|
| 29 |
+
uploaded_file = st.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"])
|
| 30 |
+
if uploaded_file is not None:
|
| 31 |
+
try:
|
| 32 |
+
image = Image.open(uploaded_file).convert("RGB")
|
| 33 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 34 |
+
|
| 35 |
+
if st.button("Classify Age"):
|
| 36 |
+
with st.spinner("Classifying..."):
|
| 37 |
+
predictions = classify_age(image)
|
| 38 |
+
st.write("### Classification Results:")
|
| 39 |
+
for pred in predictions:
|
| 40 |
+
st.write(f"**Label:** {pred['label']} | **Confidence:** {pred['score']:.2f}")
|
| 41 |
+
except Exception as e:
|
| 42 |
+
st.error(f"Error processing uploaded image: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
if __name__ == "__main__":
|
| 45 |
main()
|