Download app.py from Tapanat/image: direct link, hf CLI and curl.
- Browser
- Download file 821 Bytes
-
https://huggingface.co/spaces/Tapanat/image/resolve/main/app.py
- Command line
-
hf download hf://spaces/Tapanat/image/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Tapanat/image/resolve/main/app.py
821 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("Classification") | |
| if clicked: | |
| results = classifier(img) | |
| st.json(results) | |
| if __name__ == "__main__": | |
| main() |