Spaces:
Sleeping
Sleeping
Commit
·
766ad11
1
Parent(s):
944043e
init commit
Browse files- app.py +42 -0
- requirements.txt +100 -0
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import cv2
|
4 |
+
from huggingface_hub import hf_hub_download
|
5 |
+
from ultralytics import YOLO
|
6 |
+
|
7 |
+
checkpoint = hf_hub_download(repo_id="bulkobubulko/cap", filename="yolo11-tapas.pt")
|
8 |
+
model = YOLO(checkpoint)
|
9 |
+
model.fuse()
|
10 |
+
|
11 |
+
def plot_bl(results):
|
12 |
+
img = results[0].orig_img
|
13 |
+
names = results[0].names
|
14 |
+
scores = results[0].boxes.conf.numpy()
|
15 |
+
classes = results[0].boxes.cls.numpy()
|
16 |
+
boxes = results[0].boxes.xyxy.numpy().astype(np.int32)
|
17 |
+
|
18 |
+
num_objects = len(boxes)
|
19 |
+
|
20 |
+
for score, cls, box in zip(scores, classes, boxes):
|
21 |
+
cl_label = names[cls]
|
22 |
+
label = f"{cl_label}: {score:0.2f}"
|
23 |
+
|
24 |
+
img = cv2.rectangle(img.copy(), (box[0], box[1]), (box[2], box[3]), color=(225, 0, 225), thickness=3)
|
25 |
+
img = cv2.putText(img.copy(), label, (box[0], box[1]), fontFace=cv2.FONT_HERSHEY_SIMPLEX, fontScale=1.0, color=(255, 0, 255), thickness=2)
|
26 |
+
img = cv2.putText(img.copy(), f'num caps: {num_objects}', (100, 100), fontFace=cv2.FONT_HERSHEY_SIMPLEX, fontScale=1.0, color=(255, 0, 255), thickness=2)
|
27 |
+
return img
|
28 |
+
|
29 |
+
def predict(frame):
|
30 |
+
frame = model(frame)
|
31 |
+
frame = plot_bl(frame)
|
32 |
+
return frame
|
33 |
+
|
34 |
+
with gr.Blocks() as demo:
|
35 |
+
with gr.Row():
|
36 |
+
with gr.Column():
|
37 |
+
input_frame = gr.Image(sources=["webcam"], type="numpy")
|
38 |
+
with gr.Column():
|
39 |
+
output_img = gr.Image(streaming=True)
|
40 |
+
dep = input_frame.stream(predict, [input_frame], [output_img], time_limit=30, stream_every=0.1, concurrency_limit=30)
|
41 |
+
|
42 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiofiles==23.2.1
|
2 |
+
annotated-types==0.7.0
|
3 |
+
anyio==4.7.0
|
4 |
+
appnope==0.1.4
|
5 |
+
asttokens==3.0.0
|
6 |
+
certifi==2024.12.14
|
7 |
+
charset-normalizer==3.4.1
|
8 |
+
click==8.1.8
|
9 |
+
comm==0.2.2
|
10 |
+
contourpy==1.3.1
|
11 |
+
cycler==0.12.1
|
12 |
+
debugpy==1.8.11
|
13 |
+
decorator==5.1.1
|
14 |
+
executing==2.1.0
|
15 |
+
fastapi==0.115.6
|
16 |
+
ffmpy==0.5.0
|
17 |
+
filelock==3.16.1
|
18 |
+
fonttools==4.55.3
|
19 |
+
fsspec==2024.12.0
|
20 |
+
gradio==5.9.1
|
21 |
+
gradio_client==1.5.2
|
22 |
+
h11==0.14.0
|
23 |
+
httpcore==1.0.7
|
24 |
+
httpx==0.28.1
|
25 |
+
huggingface-hub==0.27.0
|
26 |
+
idna==3.10
|
27 |
+
ipykernel==6.29.5
|
28 |
+
ipython==8.31.0
|
29 |
+
jedi==0.19.2
|
30 |
+
Jinja2==3.1.5
|
31 |
+
jupyter_client==8.6.3
|
32 |
+
jupyter_core==5.7.2
|
33 |
+
kiwisolver==1.4.7
|
34 |
+
lap==0.5.12
|
35 |
+
markdown-it-py==3.0.0
|
36 |
+
MarkupSafe==2.1.5
|
37 |
+
matplotlib==3.10.0
|
38 |
+
matplotlib-inline==0.1.7
|
39 |
+
mdurl==0.1.2
|
40 |
+
mpmath==1.3.0
|
41 |
+
nest-asyncio==1.6.0
|
42 |
+
networkx==3.4.2
|
43 |
+
numpy==1.26.4
|
44 |
+
opencv-python==4.10.0.84
|
45 |
+
orjson==3.10.12
|
46 |
+
packaging==24.2
|
47 |
+
pandas==2.2.3
|
48 |
+
parso==0.8.4
|
49 |
+
pexpect==4.9.0
|
50 |
+
pillow==11.0.0
|
51 |
+
platformdirs==4.3.6
|
52 |
+
prompt_toolkit==3.0.48
|
53 |
+
psutil==6.1.1
|
54 |
+
ptyprocess==0.7.0
|
55 |
+
pure_eval==0.2.3
|
56 |
+
py-cpuinfo==9.0.0
|
57 |
+
pydantic==2.10.4
|
58 |
+
pydantic_core==2.27.2
|
59 |
+
pydub==0.25.1
|
60 |
+
Pygments==2.18.0
|
61 |
+
pyparsing==3.2.0
|
62 |
+
python-dateutil==2.9.0.post0
|
63 |
+
python-multipart==0.0.20
|
64 |
+
pytz==2024.2
|
65 |
+
PyYAML==6.0.2
|
66 |
+
pyzmq==26.2.0
|
67 |
+
regex==2024.11.6
|
68 |
+
requests==2.32.3
|
69 |
+
rich==13.9.4
|
70 |
+
ruff==0.8.4
|
71 |
+
safehttpx==0.1.6
|
72 |
+
safetensors==0.4.5
|
73 |
+
scipy==1.14.1
|
74 |
+
seaborn==0.13.2
|
75 |
+
semantic-version==2.10.0
|
76 |
+
setuptools==75.6.0
|
77 |
+
shapely==2.0.6
|
78 |
+
shellingham==1.5.4
|
79 |
+
six==1.17.0
|
80 |
+
sniffio==1.3.1
|
81 |
+
stack-data==0.6.3
|
82 |
+
starlette==0.41.3
|
83 |
+
sympy==1.13.1
|
84 |
+
tokenizers==0.21.0
|
85 |
+
tomlkit==0.13.2
|
86 |
+
torch==2.5.1
|
87 |
+
torchvision==0.20.1
|
88 |
+
tornado==6.4.2
|
89 |
+
tqdm==4.67.1
|
90 |
+
traitlets==5.14.3
|
91 |
+
transformers==4.47.1
|
92 |
+
typer==0.15.1
|
93 |
+
typing_extensions==4.12.2
|
94 |
+
tzdata==2024.2
|
95 |
+
ultralytics==8.3.55
|
96 |
+
ultralytics-thop==2.0.13
|
97 |
+
urllib3==2.3.0
|
98 |
+
uvicorn==0.34.0
|
99 |
+
wcwidth==0.2.13
|
100 |
+
websockets==14.1
|