Wisdom882 commited on
Commit
0262910
1 Parent(s): 0d1ae5e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+ from transformers import BeitFeatureExtractor, BeitForImageClassification
4
+ from PIL import Image
5
+ import requests
6
+
7
+ pipeline = pipeline(task = "image-classification", model = "microsoft/beit-base-patch16-224-pt22k-ft22k")
8
+
9
+ st.title("Predict the class of an image")
10
+
11
+ file_name = st.file_uploader("Upload an image here")
12
+
13
+ if file_name is not None:
14
+ col1, col2 = st.columns(2)
15
+
16
+ image = Image.open(file_name)
17
+ col1.image(image, use_column_width=True)
18
+ predictions = pipeline(image)
19
+
20
+ col2.header("Probabilities")
21
+ for p in predictions:
22
+ col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
23
+
24
+