Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
#pipeline 1
|
6 |
+
generator = pipeline("fill-mask", model="distilbert/distilbert-base-uncased")
|
7 |
+
|
8 |
+
#pipeline 2
|
9 |
+
classifier = pipeline("text-classification", model="swangfr/distilbert-multi-label-amazon", return_all_scores=True)
|
10 |
+
|
11 |
+
|
12 |
+
# Streamlit application title
|
13 |
+
st.title("Amazon Product Image classifier")
|
14 |
+
st.write("Classification for 24 categories")
|
15 |
+
|
16 |
+
#upload image file
|
17 |
+
file_name = st.file_uploader("Upload a product image file")
|
18 |
+
|
19 |
+
if st.button("Classify") & file_name is not None:
|
20 |
+
col1, col2 = st.columns(2)
|
21 |
+
|
22 |
+
image = Image.open(file_name)
|
23 |
+
col1.image(image, use_column_width=True)
|
24 |
+
generation = generator(image)
|
25 |
+
prediction = classifier(str(generation[0]['generated_text']))
|
26 |
+
|
27 |
+
col2.header("Probabilities")
|
28 |
+
for p in predictions:
|
29 |
+
col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
|