Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -49,6 +49,12 @@ with col2:
|
|
| 49 |
st.session_state.example_image = EXAMPLE_2
|
| 50 |
st.session_state.example_loaded = True
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
# Process the image and display results
|
| 53 |
if uploaded_file is not None:
|
| 54 |
# Process uploaded image
|
|
@@ -57,12 +63,15 @@ if uploaded_file is not None:
|
|
| 57 |
|
| 58 |
with st.spinner("Analyzing age..."):
|
| 59 |
predictions = pipe(image)
|
|
|
|
| 60 |
|
| 61 |
-
# Display
|
| 62 |
-
st.markdown("###
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
| 66 |
|
| 67 |
elif 'example_loaded' in st.session_state and st.session_state.example_loaded:
|
| 68 |
# Process example image
|
|
@@ -74,18 +83,21 @@ elif 'example_loaded' in st.session_state and st.session_state.example_loaded:
|
|
| 74 |
with st.spinner("Analyzing age..."):
|
| 75 |
# Pass the actual PIL Image object to the pipeline
|
| 76 |
predictions = pipe(image)
|
|
|
|
| 77 |
|
| 78 |
-
# Display
|
| 79 |
-
st.markdown("###
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
| 83 |
|
| 84 |
# Add information about the model
|
| 85 |
st.markdown("---")
|
| 86 |
st.markdown("### About the Model")
|
| 87 |
st.markdown("""
|
| 88 |
This app uses the `nateraw/vit-age-classifier` model from Hugging Face, which classifies
|
| 89 |
-
images into age groups like "0-2", "3-9", "10-19", etc. The
|
| 90 |
-
|
| 91 |
""")
|
|
|
|
| 49 |
st.session_state.example_image = EXAMPLE_2
|
| 50 |
st.session_state.example_loaded = True
|
| 51 |
|
| 52 |
+
# Function to get top prediction
|
| 53 |
+
def get_top_prediction(predictions):
|
| 54 |
+
# Get the prediction with highest confidence
|
| 55 |
+
top_prediction = max(predictions, key=lambda x: x['score'])
|
| 56 |
+
return top_prediction
|
| 57 |
+
|
| 58 |
# Process the image and display results
|
| 59 |
if uploaded_file is not None:
|
| 60 |
# Process uploaded image
|
|
|
|
| 63 |
|
| 64 |
with st.spinner("Analyzing age..."):
|
| 65 |
predictions = pipe(image)
|
| 66 |
+
top_pred = get_top_prediction(predictions)
|
| 67 |
|
| 68 |
+
# Display result
|
| 69 |
+
st.markdown("### Result:")
|
| 70 |
+
st.metric(
|
| 71 |
+
label="Predicted Age Range",
|
| 72 |
+
value=top_pred['label'],
|
| 73 |
+
delta=f"Confidence: {top_pred['score']:.2%}"
|
| 74 |
+
)
|
| 75 |
|
| 76 |
elif 'example_loaded' in st.session_state and st.session_state.example_loaded:
|
| 77 |
# Process example image
|
|
|
|
| 83 |
with st.spinner("Analyzing age..."):
|
| 84 |
# Pass the actual PIL Image object to the pipeline
|
| 85 |
predictions = pipe(image)
|
| 86 |
+
top_pred = get_top_prediction(predictions)
|
| 87 |
|
| 88 |
+
# Display result
|
| 89 |
+
st.markdown("### Result:")
|
| 90 |
+
st.metric(
|
| 91 |
+
label="Predicted Age Range",
|
| 92 |
+
value=top_pred['label'],
|
| 93 |
+
delta=f"Confidence: {top_pred['score']:.2%}"
|
| 94 |
+
)
|
| 95 |
|
| 96 |
# Add information about the model
|
| 97 |
st.markdown("---")
|
| 98 |
st.markdown("### About the Model")
|
| 99 |
st.markdown("""
|
| 100 |
This app uses the `nateraw/vit-age-classifier` model from Hugging Face, which classifies
|
| 101 |
+
images into age groups like "0-2", "3-9", "10-19", etc. The app displays only the most
|
| 102 |
+
likely age range prediction with its confidence score.
|
| 103 |
""")
|