chanelcolgate commited on
Commit
0be45a9
1 Parent(s): 6a67d29

Add application file

Browse files
Files changed (3) hide show
  1. .gitignore +30 -0
  2. app.py +102 -0
  3. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .git/
2
+ flagged/
3
+ gradio_cached_examples/
4
+ yolov8n.pt
5
+
6
+ tmp/0630d4cd9e21cbb71aadde8af8d07063d477f477.jpg
7
+ tmp/0766ddd55f53713c006822de3b7359aeedc3c10a.jpg
8
+ tmp/14756463a54c6701f38d1fd048ee1ec2cad7bb0a.jpg
9
+ tmp/1ac9d1a1c9d327b47369bcb2ed8db6d42d7890f7.jpg
10
+ tmp/22a77defac5e6b1b677ece221b2da818fcf1c1d3.jpg
11
+ tmp/29ad45df9b3cfc544ad11038c0c672b54575a4d4.jpg
12
+ tmp/37cd6e1e0b05c969d020279d0168aac9574c8c80.jpg
13
+ tmp/3e1bab1684e0fba56b99e848a5bac400d39dff0f.jpg
14
+ tmp/4a14b3aeef71692ee3c64580a151dcf2651069e4.jpg
15
+ tmp/4bed9cde4c606b5d719734d6ea431372201fc675.jpg
16
+ tmp/517f7ba0fc8c575a0c949df08b14fa68208dce24.jpg
17
+ tmp/5825095aa175acc396daf02e0840d53b513cfe26.jpg
18
+ tmp/591b606b955809a97d187d8efac007f58002005f.jpg
19
+ tmp/5b48a15348b36579a38a93fa9ceecaa8d469b063.jpg
20
+ tmp/5b77964d8e3024a252657ca4a75cb3ebbaeac074.jpg
21
+ tmp/660b91ce88146e2fa96db3d619d56145557794da.jpg
22
+ tmp/7eb4d3a70a8ba68c7c56ecaf0b98a1bc86aac46c.jpg
23
+ tmp/8cd6f1f3f9cc90e5e9adce08dd5d501f08861017.jpg
24
+ tmp/8e11944dec02c6a20716ba85b86a326aefdaf2e6.jpg
25
+ tmp/8f176a9e01c72c4462b96a8efb8c674a5d162dda.jpg
26
+ tmp/933b16fb6edf53a30beb723f8fad7e9dee620b30.jpg
27
+ tmp/98a97c135e28e50247c741ce7a1a6734132d03fc.jpg
28
+ tmp/9ca463ac20ce86875f413fc67f1e2f7828a21221.jpg
29
+ tmp/c2c6e668ecf2d31901bb8dda3a6f92ea8611631a.jpg
30
+ tmp/fb210fab276dcb4a458dff6a91f7f39403959d50.jpg
app.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import glob
3
+ from collections import Counter
4
+
5
+ import requests
6
+ import gradio as gr
7
+ from ultralyticsplus import YOLO, download_from_hub, render_result
8
+
9
+ hf_model_ids = [
10
+ "chanelcolgate/chamdiemgianhang-vsk",
11
+ "chanelcolgate/chamdiemgianhang-vsk-v2",
12
+ ]
13
+
14
+ image_paths = [
15
+ [image_path, "chanelcolgate/chamdiemgianhang-vsk-v2", 640, 0.25, 0.45]
16
+ for image_path in glob.glob("./tmp/*.jpg")
17
+ ]
18
+
19
+
20
+ def detection_image(
21
+ image=None,
22
+ hf_model_id="chanelcolgate/chamdiemgianhang-vsk-v2",
23
+ image_size=640,
24
+ conf_threshold=0.25,
25
+ iou_threshold=0.45,
26
+ ):
27
+ model_path = download_from_hub(hf_model_id)
28
+ model = YOLO(model_path)
29
+ results = model(image, imgsz=image_size, conf=conf_threshold, iou=iou_threshold)
30
+ json_result = json.loads(results[0].tojson())
31
+ class_counts = Counter(detection["name"] for detection in json_result)
32
+
33
+ render = render_result(model=model, image=image, result=results[0])
34
+ return render, class_counts
35
+
36
+
37
+ def detection_image_link(
38
+ image=None,
39
+ hf_model_id="chanelcolgate/chamdiemgianhang-vsk-v2",
40
+ image_size=640,
41
+ conf_threshold=0.25,
42
+ iou_threshold=0.45,
43
+ ):
44
+ model_path = download_from_hub(hf_model_id)
45
+ model = YOLO(model_path)
46
+ results = model(image, imgsz=image_size, conf=conf_threshold, iou=iou_threshold)
47
+ json_result = json.loads(results[0].tojson())
48
+ class_counts = Counter(detection["name"] for detection in json_result)
49
+
50
+ render = render_result(model=model, image=image, result=results[0])
51
+ return render, class_counts
52
+
53
+
54
+ title = "Cham Diem Gian Hang VSK"
55
+
56
+ interface = gr.Interface(
57
+ fn=detection_image,
58
+ inputs=[
59
+ gr.Image(type="pil"),
60
+ gr.Dropdown(hf_model_ids),
61
+ gr.Slider(minimum=320, maximum=1280, value=640, step=32, label="Image Size"),
62
+ gr.Slider(
63
+ minimum=0.0,
64
+ maximum=1.0,
65
+ value=0.25,
66
+ step=0.05,
67
+ label="Confidence Threshold",
68
+ ),
69
+ gr.Slider(
70
+ minimum=0.0, maximum=1.0, value=0.45, step=0.05, label="IOU Threshold"
71
+ ),
72
+ ],
73
+ outputs=[gr.Image(type="pil"), gr.Textbox(show_label=False)],
74
+ title=title,
75
+ examples=image_paths,
76
+ cache_examples=True if image_paths else False,
77
+ )
78
+
79
+ interface_link = gr.Interface(
80
+ fn=detection_image,
81
+ inputs=[
82
+ gr.Textbox(label="Image Link"),
83
+ gr.Dropdown(hf_model_ids),
84
+ gr.Slider(minimum=320, maximum=1280, value=640, step=32, label="Image Size"),
85
+ gr.Slider(
86
+ minimum=0.0,
87
+ maximum=1.0,
88
+ value=0.25,
89
+ step=0.05,
90
+ label="Confidence Threshold",
91
+ ),
92
+ gr.Slider(
93
+ minimum=0.0, maximum=1.0, value=0.45, step=0.05, label="IOU Threshold"
94
+ ),
95
+ ],
96
+ outputs=[gr.Image(type="pil"), gr.Textbox(show_label=False)],
97
+ title=title,
98
+ )
99
+
100
+ gr.TabbedInterface(
101
+ [interface, interface_link], tab_names=["Image inference", "Image link inference"]
102
+ ).queue().launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ requests==2.31.0
2
+ gradio==4.26.0
3
+ ultralyticsplus==0.0.29