DevBM commited on
Commit
81ad4a1
·
verified ·
1 Parent(s): 025fb6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -44
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
- 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'))
 
 
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'))