Download app.py from sanikjohn/DETR: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/spaces/sanikjohn/DETR/resolve/main/app.py
- Command line
-
hf download hf://spaces/sanikjohn/DETR/app.py
-
curl -L -o app.py https://huggingface.co/spaces/sanikjohn/DETR/resolve/main/app.py
1.11 kB
| # %% [markdown] | |
| # #### Real-Time Object Detection | |
| # %% | |
| # !pip install transformers | |
| # !pip install gradio | |
| # !pip install timm | |
| # !pip install inflect | |
| # !pip install phonemizer | |
| # %% | |
| from helper import load_image_from_url, render_results_in_image | |
| # %% | |
| from transformers import pipeline | |
| # %% | |
| from transformers.utils import logging | |
| logging.set_verbosity_error() | |
| from helper import ignore_warnings | |
| ignore_warnings() | |
| # %% | |
| # Object detection pipeline from META's DETR model | |
| od_pipe = pipeline("object-detection", "facebook/detr-resnet-50") | |
| # %% | |
| from PIL import Image | |
| # %% | |
| import os | |
| import gradio as gr | |
| # %% | |
| def get_pipeline_prediction(pil_image): | |
| pipeline_output = od_pipe(pil_image) | |
| processed_image = render_results_in_image(pil_image, pipeline_output) | |
| return processed_image | |
| # %% | |
| demo = gr.Interface( | |
| fn = get_pipeline_prediction, | |
| inputs = gr.Image(label = "Input Image", type = "pil"), | |
| outputs = gr.Image(label = "Output Image", type = "pil"), | |
| title = "Object Detection with DETR", | |
| ) | |
| # %% | |
| demo.launch(share=True, debug=True) | |
| # %% | |
| # %% | |
| # %% | |
| # %% | |
| # %% [markdown] | |
| # | |