nehulagrawal
commited on
Commit
·
d314c8a
1
Parent(s):
c025187
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from ultralyticsplus import YOLO, render_result
|
4 |
+
|
5 |
+
|
6 |
+
# Images
|
7 |
+
torch.hub.download_url_to_file('https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftexashafts.com%2Fwp-content%2Fuploads%2F2016%2F04%2Fconstruction-worker.jpg', 'one.jpg')
|
8 |
+
torch.hub.download_url_to_file(
|
9 |
+
'https://www.pearsonkoutcherlaw.com/wp-content/uploads/2020/06/Construction-Workers.jpg', 'two.jpg')
|
10 |
+
torch.hub.download_url_to_file(
|
11 |
+
'https://nssgroup.com/wp-content/uploads/2019/02/Building-maintenance-blog.jpg', 'three.jpg')
|
12 |
+
|
13 |
+
|
14 |
+
def yoloV8_func(image: gr.inputs.Image = None,
|
15 |
+
image_size: gr.inputs.Slider = 640,
|
16 |
+
conf_threshold: gr.inputs.Slider = 0.4,
|
17 |
+
iou_threshold: gr.inputs.Slider = 0.50):
|
18 |
+
"""_summary_
|
19 |
+
Args:
|
20 |
+
image (gr.inputs.Image, optional): _description_. Defaults to None.
|
21 |
+
image_size (gr.inputs.Slider, optional): _description_. Defaults to 640.
|
22 |
+
conf_threshold (gr.inputs.Slider, optional): _description_. Defaults to 0.4.
|
23 |
+
iou_threshold (gr.inputs.Slider, optional): _description_. Defaults to 0.50.
|
24 |
+
"""
|
25 |
+
model_path = "best.pt"
|
26 |
+
model = YOLO("foduucom/table-detection-and-extraction")
|
27 |
+
|
28 |
+
results = model.predict(image,
|
29 |
+
conf=conf_threshold,
|
30 |
+
iou=iou_threshold,
|
31 |
+
imgsz=image_size)
|
32 |
+
|
33 |
+
# observe results
|
34 |
+
box = results[0].boxes
|
35 |
+
print("Object type:", box.cls)
|
36 |
+
print("Coordinates:", box.xyxy)
|
37 |
+
print("Probability:", box.conf)
|
38 |
+
render = render_result(model=model, image=image, result=results[0])
|
39 |
+
return render
|
40 |
+
|
41 |
+
|
42 |
+
inputs = [
|
43 |
+
gr.inputs.Image(type="filepath", label="Input Image"),
|
44 |
+
gr.inputs.Slider(minimum=320, maximum=1280, default=640,
|
45 |
+
step=32, label="Image Size"),
|
46 |
+
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.25,
|
47 |
+
step=0.05, label="Confidence Threshold"),
|
48 |
+
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.45,
|
49 |
+
step=0.05, label="IOU Threshold"),
|
50 |
+
]
|
51 |
+
|
52 |
+
|
53 |
+
outputs = gr.outputs.Image(type="filepath", label="Output Image")
|
54 |
+
title = "YOLOv8 101: Custome Object Detection on Construction Workers "
|
55 |
+
|
56 |
+
|
57 |
+
examples = [['one.jpg', 640, 0.5, 0.7],
|
58 |
+
['two.jpg', 800, 0.5, 0.6],
|
59 |
+
['three.jpg', 900, 0.5, 0.8]]
|
60 |
+
|
61 |
+
yolo_app = gr.Interface(
|
62 |
+
fn=yoloV8_func,
|
63 |
+
inputs=inputs,
|
64 |
+
outputs=outputs,
|
65 |
+
title=title,
|
66 |
+
examples=examples,
|
67 |
+
cache_examples=True,
|
68 |
+
#theme='huggingface',
|
69 |
+
)
|
70 |
+
yolo_app.launch(debug=True, enable_queue=True)
|