Spaces:
Runtime error
Runtime error
import gradio as gr | |
from PIL import Image | |
import numpy as np | |
import os | |
title = """<h1 id="title">App Detection</h1>""" | |
models = ["nickmuchi/yolos-small-finetuned-masks","nickmuchi/yolos-base-finetuned-masks"] | |
urls = ["https://api.time.com/wp-content/uploads/2020/03/hong-kong-mask-admiralty.jpg","https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ7wiGZhgAFuIpwFJzbpv8kUMM_Q3WaAWYf5NpSJduxvHQ7V2WnqZ0wMWS6cK5gvlfPGxc&usqp=CAU"] | |
css = ''' | |
h1#title { | |
text-align: center; | |
} | |
''' | |
demo = gr.Blocks(css=css) | |
with demo: | |
gr.Markdown(title) | |
options = gr.Dropdown(choices=models,label='Detection',show_label=True) | |
slider_input = gr.Slider(minimum=0.2,maximum=1,value=0.5,step=0.1,label='Prediction Threshold') | |
with gr.Tabs(): | |
with gr.TabItem('Image URL'): | |
with gr.Row(): | |
with gr.Column(): | |
url_input = gr.Textbox(lines=2,label='Enter valid image URL here..') | |
original_image = gr.Image(shape=(750,750)) | |
with gr.Column(): | |
img_output_from_url = gr.Image(shape=(750,750)) | |
with gr.Row(): | |
example_url = gr.Dataset(components=[url_input],samples=[[str(url)] for url in urls]) | |
url_but = gr.Button('Detect') | |
with gr.TabItem('Image Upload'): | |
with gr.Row(): | |
img_input = gr.Image(type='pil',shape=(750,750)) | |
img_output_from_upload= gr.Image(shape=(750,750)) | |
with gr.Row(): | |
example_images = gr.Dataset(components=[img_input], | |
samples=[[path.as_posix()] for path in sorted(pathlib.Path('images').rglob('*.j*g'))]) | |
img_but = gr.Button('Detect') | |
with gr.TabItem('WebCam'): | |
with gr.Row(): | |
web_input = gr.Image(source='webcam',type='pil',shape=(750,750),streaming=True) | |
img_output_from_webcam= gr.Image(shape=(750,750)) | |
cam_but = gr.Button('Detect') | |
url_but.click(detect_objects,inputs=[options,url_input,img_input,web_input,slider_input],outputs=[img_output_from_url],queue=True) | |
img_but.click(detect_objects,inputs=[options,url_input,img_input,web_input,slider_input],outputs=[img_output_from_upload],queue=True) | |
cam_but.click(detect_objects,inputs=[options,url_input,img_input,web_input,slider_input],outputs=[img_output_from_webcam],queue=True) | |
example_images.click(fn=set_example_image,inputs=[example_images],outputs=[img_input]) | |
example_url.click(fn=set_example_url,inputs=[example_url],outputs=[url_input,original_image]) | |
demo.launch(debug=True,enable_queue=True) | |