mookkanvas commited on
Commit
6009e45
1 Parent(s): cf4cf1c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ from PIL import Image
3
+ import streamlit as st
4
+ from transformers import pipeline
5
+
6
+
7
+ pipeline = pipeline(task="image-classification", model="nateraw/vit-age-classifier")
8
+
9
+ def predict(image):
10
+ predictions = pipeline(image)
11
+ return {p["label"]: p["score"] for p in predictions}
12
+
13
+ def main():
14
+ st.title("Age Classification From Image")
15
+
16
+ with st.form("my_form"):
17
+ uploaded_file = st.file_uploader("Choose an image file", type=["jpg", "jpeg", "png"])
18
+
19
+ if uploaded_file is not None:
20
+ # Display the uploaded image
21
+ image = Image.open(uploaded_file)
22
+ st.image(image, caption="Your uploaded Image", use_column_width=True)
23
+ clicked = st.form_submit_button("Press to predict")
24
+ if clicked:
25
+ results = predict(image)
26
+ k = []
27
+ v = []
28
+ for key, value in results.items():
29
+ value = round(value*100,2)
30
+ v.append(value)
31
+ k.append(key)
32
+ vp = [str(item) + '%' for item in v]
33
+ result = k[0]
34
+ st.success('The predicted age is {}'.format(result))
35
+ df = pd.DataFrame({'Prediction': k,'Accuracy':vp})
36
+ st.dataframe(df,hide_index=True)
37
+
38
+ if __name__ == "__main__":
39
+ main()