Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
from PIL import Image
|
4 |
+
import requests
|
5 |
+
|
6 |
+
classifier = pipeline("image-classification", model="google/vit-base-patch16-224")
|
7 |
+
def get_img_from_url(url):
|
8 |
+
return Image.open(requests.get(url, stream=True).raw)
|
9 |
+
|
10 |
+
def main():
|
11 |
+
st.title("image-classification")
|
12 |
+
|
13 |
+
with st.form("image"):
|
14 |
+
|
15 |
+
url = st.text_input("URL to some image", "https://images.livemint.com/img/2022/08/01/600x338/Cat-andriyko-podilnyk-RCfi7vgJjUY-unsplash_1659328989095_1659328998370_1659328998370.jpg")
|
16 |
+
img = get_img_from_url(url)
|
17 |
+
# clicked==True only when the button is clicked
|
18 |
+
clicked = st.form_submit_button("Submit")
|
19 |
+
if clicked:
|
20 |
+
results = classifier(img)
|
21 |
+
st.json(results)
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
+
if __name__ == "__main__":
|
27 |
+
main()
|