ClassCat commited on
Commit
783a0a3
1 Parent(s): 5e03e65

add app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -10
app.py CHANGED
@@ -59,8 +59,6 @@ def get_figure(in_pil_img, in_results):
59
 
60
 
61
  def infer(in_model, in_threshold, in_pil_img):
62
- print(type(in_pil_img))
63
- print(threshold)
64
  inputs = image_processor_tiny(images=in_pil_img, return_tensors="pt")
65
  outputs = model_tiny(**inputs)
66
 
@@ -81,23 +79,36 @@ def infer(in_model, in_threshold, in_pil_img):
81
  return output_pil_img
82
 
83
 
84
- #from transformers.models.flava import modeling_flava
85
- with gr.Blocks(css=".gradio-container {background:lightyellow;color:red;}", title="テスト"
86
  ) as demo:
87
  #sample_index = gr.State([])
88
 
89
- gr.HTML('<div style="font-size:12pt; text-align:center; color:yellow;">MNIST 分類器</div>')
90
 
91
- model = gr.Radio(["detr-resnet-50", "detr-resnet-101"], value="detr-resnet-50")
 
 
 
 
 
 
92
 
93
  with gr.Row():
94
- input_image = gr.Image(label="", type="pil")
95
- output_image = gr.Image(type="pil")
96
-
 
 
 
 
97
 
98
  threshold = gr.Slider(0, 1.0, value=0.9, label='threshold')
99
 
100
- send_btn = gr.Button("予測する")
 
 
 
101
  send_btn.click(fn=infer, inputs=[model, threshold, input_image], outputs=[output_image])
102
 
103
  #demo.queue()
 
59
 
60
 
61
  def infer(in_model, in_threshold, in_pil_img):
 
 
62
  inputs = image_processor_tiny(images=in_pil_img, return_tensors="pt")
63
  outputs = model_tiny(**inputs)
64
 
 
79
  return output_pil_img
80
 
81
 
82
+ with gr.Blocks(title="YOLOS Object Detection - ClassCat",
83
+ css=".gradio-container {background:lightyellow;}"
84
  ) as demo:
85
  #sample_index = gr.State([])
86
 
87
+ gr.HTML("""<div style="font-family:'Times New Roman', 'Serif'; font-size:16pt; font-weight:bold; text-align:center; color:royalblue;">YOLOS Object Detection</div>""")
88
 
89
+ gr.HTML("""<h4 style="color:navy;">1. Select a model.</h4>""")
90
+
91
+ model = gr.Radio(["yolos-tiny", "yolos-small"], value="yolos-tiny")
92
+
93
+ gr.HTML("""<br/>""")
94
+ gr.HTML("""<h4 style="color:navy;">2-a. Select an example by clicking a thumbnail below.</h4>""")
95
+ gr.HTML("""<h4 style="color:navy;">2-b. Or upload an image by clicking on the canvas.</h4>""")
96
 
97
  with gr.Row():
98
+ input_image = gr.Image(label="Input image", type="pil")
99
+ output_image = gr.Image(label="Output image with predicted instances", type="pil")
100
+
101
+ gr.Examples(['samples/cats.jpg', 'samples/detectron2.png', 'samples/cat.jpg', 'samples/hotdog.jpg'], inputs=input_image)
102
+
103
+ gr.HTML("""<br/>""")
104
+ gr.HTML("""<h4 style="color:navy;">3. Set threshold value (default to 0.9)</h4>""")
105
 
106
  threshold = gr.Slider(0, 1.0, value=0.9, label='threshold')
107
 
108
+ gr.HTML("""<br/>""")
109
+ gr.HTML("""<h4 style="color:navy;">4. Then, click "Infer" button to predict object instances. It will take about 10 seconds (on cpu)</h4>""")
110
+
111
+ send_btn = gr.Button("Infer")
112
  send_btn.click(fn=infer, inputs=[model, threshold, input_image], outputs=[output_image])
113
 
114
  #demo.queue()