Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| from transformers import pipeline | |
| import matplotlib.pyplot as plt | |
| import requests | |
| from PIL import Image | |
| obj_model = pipeline("object-detection", model="facebook/detr-resnet-50") | |
| def get_img_from_url(url): | |
| return Image.open(requests.get(url, stream=True).raw) | |
| def main(): | |
| st.title("Object Detection") | |
| with st.form("text_field"): | |
| url = st.text_input("Enter an image URL", "https://images.unsplash.com/photo-1543852786-1cf6624b9987?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=987&q=80") | |
| st.write("*We recommend to use Unsplash website for browsing an image,[click here!](https://unsplash.com/)") | |
| img = get_img_from_url(url) | |
| # clicked==True only when the button is clicked | |
| clicked = st.form_submit_button("Submit") | |
| if clicked: | |
| results = obj_model(img) | |
| st.write("**ββββββββββββββββββββββ**") | |
| st.write("**Input image:**") | |
| st.image(img) | |
| st.json(results) | |
| if __name__ == "__main__": | |
| main() |