Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- main.py +44 -0
- requirements.txt +3 -0
main.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import requests
|
| 4 |
+
from PIL import Image
|
| 5 |
+
from io import BytesIO
|
| 6 |
+
import pandas as pd
|
| 7 |
+
|
| 8 |
+
st.subheader("Image Classification", divider='orange')
|
| 9 |
+
|
| 10 |
+
if st.toggle(label='Show Pipe4'):
|
| 11 |
+
models = [
|
| 12 |
+
'google/vit-base-patch16-224',
|
| 13 |
+
'microsoft/resnet-50',
|
| 14 |
+
'facebook/deit-base-distilled-patch16-224',
|
| 15 |
+
'facebook/convnext-large-224',
|
| 16 |
+
'apple/mobilevit-small'
|
| 17 |
+
]
|
| 18 |
+
model_name = st.selectbox(
|
| 19 |
+
label='Select Model',
|
| 20 |
+
options=models,
|
| 21 |
+
placeholder='google/vit-base-patch16-224',
|
| 22 |
+
)
|
| 23 |
+
pipe = pipeline("image-classification", model=model_name)
|
| 24 |
+
url = 'https://media.istockphoto.com/id/182756302/photo/hot-dog-with-grilled-peppers.jpg?s=1024x1024&w=is&k=20&c=NCHo2P94a-PfRDKzWSe4h6oACQZ-_ubZqUBj5CMSEWY='
|
| 25 |
+
response = requests.get(url=url)
|
| 26 |
+
image_bytes = BytesIO(response.content)
|
| 27 |
+
image = Image.open(image_bytes)
|
| 28 |
+
# image = Image.open(BytesIO(requests.get(url).content))
|
| 29 |
+
# use_default = st.checkbox(label='Use default image')
|
| 30 |
+
file = st.file_uploader(label='Upload image')
|
| 31 |
+
if file is not None:
|
| 32 |
+
image = Image.open(file)
|
| 33 |
+
|
| 34 |
+
res = pipe(image)
|
| 35 |
+
if st.toggle(label='Show row data'):
|
| 36 |
+
st.write(res)
|
| 37 |
+
p = pd.DataFrame(res)
|
| 38 |
+
p = p.sort_values(by='score',ascending=False)
|
| 39 |
+
col1, col2 = st.columns(2)
|
| 40 |
+
col1.write(image)
|
| 41 |
+
col2.write(p['label'])
|
| 42 |
+
st.bar_chart(p.set_index('label'))
|
| 43 |
+
st.area_chart(p.set_index('label'))
|
| 44 |
+
# col2.bar_chart(p.set_index('label'))
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
transformers
|
| 3 |
+
pandas
|