mmmm / app.py
yiw's picture
Create app.py
8f8ddc7
raw
history blame contribute delete
813 Bytes
import streamlit as st
from transformers import pipeline
from PIL import Image
import requests
classifier = pipeline("image-classification", model="google/vit-base-patch16-224")
def get_img_from_url(url):
return Image.open(requests.get(url, stream=True).raw)
def main():
st.title("image-classification")
with st.form("image"):
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")
img = get_img_from_url(url)
# clicked==True only when the button is clicked
clicked = st.form_submit_button("Submit")
if clicked:
results = classifier(img)
st.json(results)
if __name__ == "__main__":
main()