File size: 1,124 Bytes
f90ae9e
 
 
 
 
 
 
 
 
 
d4a539c
f90ae9e
 
 
 
0994472
9dd7f9a
f90ae9e
 
 
 
 
0994472
265f683
f7179a6
6c36af7
 
20085ae
6c36af7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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()