CoolFace
Apppublic

Erion23/ObjectDetectionEx1

sourceHugging Faceapache-2.0updated 4y agoView on Hugging Face
0likes
app.py28 linesDownload Raw Back to root
1import streamlit as st2from transformers import pipeline3import matplotlib.pyplot as plt4import requests5from PIL import Image6 7obj_model = pipeline("object-detection", model="facebook/detr-resnet-50")8 9def get_img_from_url(url):10    return Image.open(requests.get(url, stream=True).raw)11    12def main():13    st.title("Object Detection WebApp Exercise 1")14 15    with st.form("text_field"):16        url = st.text_input("Enter the URL of an image", "https://static.onecms.io/wp-content/uploads/sites/47/2020/09/22/biking-with-dog-1208975567-2000.jpg")17        img = get_img_from_url(url)18        19        # when the button is clicked the form is submitted (object detection/prediction starts)20        clicked = st.form_submit_button("Predict")21        if clicked:22          results = obj_model(img)23          st.write("**Input image:**")24          st.image(img)25          st.json(results)26          27if __name__ == "__main__":28    main()