Update the labels in app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from PIL import ImageDraw
|
|
|
4 |
|
5 |
# Model
|
6 |
model_path = 'model_torch.pt'
|
@@ -17,14 +18,17 @@ def detect_objects(image):
|
|
17 |
|
18 |
detections = model(image)
|
19 |
|
|
|
|
|
20 |
for detection in detections.xyxy[0]:
|
21 |
|
22 |
x1, y1, x2, y2, p, category_id = detection
|
23 |
x1, y1, x2, y2, category_id = int(x1), int(y1), int(x2), int(y2), int(category_id)
|
24 |
draw.rectangle((x1, y1, x2, y2), outline=colors[category_id], width=4)
|
25 |
draw.text((x1, y1), labels[category_id], colors[category_id])
|
|
|
26 |
|
27 |
-
return image
|
28 |
|
29 |
|
30 |
demo = gr.Blocks()#(css=css)
|
@@ -32,8 +36,6 @@ demo = gr.Blocks()#(css=css)
|
|
32 |
title = '# 3D print failures detection App'
|
33 |
description = 'App for detect errors in the 3D printing'
|
34 |
|
35 |
-
urls = ["https://c8.alamy.com/comp/J2AB4K/the-new-york-stock-exchange-on-the-wall-street-in-new-york-J2AB4K.jpg"]
|
36 |
-
|
37 |
with demo:
|
38 |
gr.Markdown(title)
|
39 |
gr.Markdown(description)
|
@@ -41,18 +43,20 @@ with demo:
|
|
41 |
with gr.Tabs():
|
42 |
with gr.TabItem('Image Upload'):
|
43 |
with gr.Row():
|
44 |
-
img_input = gr.Image(type='pil')
|
45 |
-
img_output= gr.Image()
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
51 |
|
|
|
|
|
|
|
52 |
img_button = gr.Button('Detect')
|
53 |
|
54 |
-
|
55 |
-
img_button.click(detect_objects,inputs=img_input,outputs=img_output)
|
56 |
|
57 |
|
58 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from PIL import ImageDraw
|
4 |
+
import pathlib
|
5 |
|
6 |
# Model
|
7 |
model_path = 'model_torch.pt'
|
|
|
18 |
|
19 |
detections = model(image)
|
20 |
|
21 |
+
probabilities = {}
|
22 |
+
|
23 |
for detection in detections.xyxy[0]:
|
24 |
|
25 |
x1, y1, x2, y2, p, category_id = detection
|
26 |
x1, y1, x2, y2, category_id = int(x1), int(y1), int(x2), int(y2), int(category_id)
|
27 |
draw.rectangle((x1, y1, x2, y2), outline=colors[category_id], width=4)
|
28 |
draw.text((x1, y1), labels[category_id], colors[category_id])
|
29 |
+
probabilities[labels[category_id]] = float(p)
|
30 |
|
31 |
+
return [image, probabilities]
|
32 |
|
33 |
|
34 |
demo = gr.Blocks()#(css=css)
|
|
|
36 |
title = '# 3D print failures detection App'
|
37 |
description = 'App for detect errors in the 3D printing'
|
38 |
|
|
|
|
|
39 |
with demo:
|
40 |
gr.Markdown(title)
|
41 |
gr.Markdown(description)
|
|
|
43 |
with gr.Tabs():
|
44 |
with gr.TabItem('Image Upload'):
|
45 |
with gr.Row():
|
|
|
|
|
46 |
|
47 |
+
with gr.Column():
|
48 |
+
img_input = gr.Image(type='pil')
|
49 |
+
examples_images2 = gr.Examples(examples = [[path.as_posix()] for path in sorted(pathlib.Path('images').rglob('*.jpg'))],
|
50 |
+
inputs=img_input)
|
51 |
+
labels_bars = gr.Label(label = "Categories")
|
52 |
+
print(labels_bars)
|
53 |
|
54 |
+
with gr.Column():
|
55 |
+
img_output= gr.Image()
|
56 |
+
|
57 |
img_button = gr.Button('Detect')
|
58 |
|
59 |
+
img_button.click(detect_objects,inputs=img_input,outputs=[img_output, labels_bars])
|
|
|
60 |
|
61 |
|
62 |
if __name__ == "__main__":
|