Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,45 @@
|
|
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 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
#
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
p =
|
39 |
-
|
40 |
-
col1.
|
41 |
-
|
42 |
-
|
43 |
-
st.
|
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 |
+
'timm/resnet50.a1_in1k'
|
18 |
+
]
|
19 |
+
model_name = st.selectbox(
|
20 |
+
label='Select Model',
|
21 |
+
options=models,
|
22 |
+
placeholder='google/vit-base-patch16-224',
|
23 |
+
)
|
24 |
+
pipe = pipeline("image-classification", model=model_name)
|
25 |
+
url = 'https://media.istockphoto.com/id/182756302/photo/hot-dog-with-grilled-peppers.jpg?s=1024x1024&w=is&k=20&c=NCHo2P94a-PfRDKzWSe4h6oACQZ-_ubZqUBj5CMSEWY='
|
26 |
+
response = requests.get(url=url)
|
27 |
+
image_bytes = BytesIO(response.content)
|
28 |
+
image = Image.open(image_bytes)
|
29 |
+
# image = Image.open(BytesIO(requests.get(url).content))
|
30 |
+
# use_default = st.checkbox(label='Use default image')
|
31 |
+
file = st.file_uploader(label='Upload image')
|
32 |
+
if file is not None:
|
33 |
+
image = Image.open(file)
|
34 |
+
|
35 |
+
res = pipe(image)
|
36 |
+
if st.toggle(label='Show row data'):
|
37 |
+
st.write(res)
|
38 |
+
p = pd.DataFrame(res)
|
39 |
+
p = p.sort_values(by='score',ascending=False)
|
40 |
+
col1, col2 = st.columns(2)
|
41 |
+
col1.write(image)
|
42 |
+
col2.write(p['label'])
|
43 |
+
st.bar_chart(p.set_index('label'))
|
44 |
+
st.area_chart(p.set_index('label'))
|
45 |
+
# col2.bar_chart(p.set_index('label'))
|