Eric2983 commited on
Commit
6aaf5bb
1 Parent(s): a55bf0e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -8
app.py CHANGED
@@ -4,11 +4,63 @@ from PIL import Image
4
  import numpy as np
5
  import os
6
 
7
- # Create the Gradio app
8
- app = gr.Interface(
9
- inputs=gr.Image(type="pil"),
10
- title="App Detection"
11
- )
12
-
13
- # Run the app
14
- app.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  import numpy as np
5
  import os
6
 
7
+ title = """<h1 id="title">App Detection</h1>"""
8
+
9
+ models = ["nickmuchi/yolos-small-finetuned-masks","nickmuchi/yolos-base-finetuned-masks"]
10
+ 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"]
11
+
12
+ css = '''
13
+ h1#title {
14
+ text-align: center;
15
+ }
16
+ '''
17
+ demo = gr.Blocks(css=css)
18
+
19
+ with demo:
20
+ with gr.Box():
21
+
22
+ gr.Markdown(title)
23
+ options = gr.Dropdown(choices=models,label='Detection',show_label=True)
24
+ slider_input = gr.Slider(minimum=0.2,maximum=1,value=0.5,step=0.1,label='Prediction Threshold')
25
+
26
+ with gr.Tabs():
27
+ with gr.TabItem('Image URL'):
28
+ with gr.Row():
29
+ with gr.Column():
30
+ url_input = gr.Textbox(lines=2,label='Enter valid image URL here..')
31
+ original_image = gr.Image(shape=(750,750))
32
+ with gr.Column():
33
+ img_output_from_url = gr.Image(shape=(750,750))
34
+
35
+ with gr.Row():
36
+ example_url = gr.Dataset(components=[url_input],samples=[[str(url)] for url in urls])
37
+
38
+ url_but = gr.Button('Detect')
39
+
40
+ with gr.TabItem('Image Upload'):
41
+ with gr.Row():
42
+ img_input = gr.Image(type='pil',shape=(750,750))
43
+ img_output_from_upload= gr.Image(shape=(750,750))
44
+
45
+ with gr.Row():
46
+ example_images = gr.Dataset(components=[img_input],
47
+ samples=[[path.as_posix()] for path in sorted(pathlib.Path('images').rglob('*.j*g'))])
48
+
49
+
50
+ img_but = gr.Button('Detect')
51
+
52
+ with gr.TabItem('WebCam'):
53
+ with gr.Row():
54
+ web_input = gr.Image(source='webcam',type='pil',shape=(750,750),streaming=True)
55
+ img_output_from_webcam= gr.Image(shape=(750,750))
56
+
57
+ cam_but = gr.Button('Detect')
58
+
59
+ url_but.click(detect_objects,inputs=[options,url_input,img_input,web_input,slider_input],outputs=[img_output_from_url],queue=True)
60
+ img_but.click(detect_objects,inputs=[options,url_input,img_input,web_input,slider_input],outputs=[img_output_from_upload],queue=True)
61
+ cam_but.click(detect_objects,inputs=[options,url_input,img_input,web_input,slider_input],outputs=[img_output_from_webcam],queue=True)
62
+ example_images.click(fn=set_example_image,inputs=[example_images],outputs=[img_input])
63
+ example_url.click(fn=set_example_url,inputs=[example_url],outputs=[url_input,original_image])
64
+
65
+
66
+ demo.launch(debug=True,enable_queue=True)