Spaces:
Running
Running
RizwanMunawar
commited on
Commit
β’
7585ca6
1
Parent(s):
9d30ba8
Add image inference support
Browse files- .gitignore +173 -0
- app.py +44 -0
.gitignore
ADDED
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Byte-compiled / optimized / DLL files
|
2 |
+
__pycache__/
|
3 |
+
*.py[cod]
|
4 |
+
*$py.class
|
5 |
+
|
6 |
+
# C extensions
|
7 |
+
*.so
|
8 |
+
|
9 |
+
# Distribution / packaging
|
10 |
+
.Python
|
11 |
+
build/
|
12 |
+
develop-eggs/
|
13 |
+
dist/
|
14 |
+
downloads/
|
15 |
+
eggs/
|
16 |
+
.eggs/
|
17 |
+
lib/
|
18 |
+
lib64/
|
19 |
+
parts/
|
20 |
+
sdist/
|
21 |
+
var/
|
22 |
+
wheels/
|
23 |
+
pip-wheel-metadata/
|
24 |
+
share/python-wheels/
|
25 |
+
*.egg-info/
|
26 |
+
.installed.cfg
|
27 |
+
*.egg
|
28 |
+
MANIFEST
|
29 |
+
requirements.txt
|
30 |
+
setup.py
|
31 |
+
ultralytics.egg-info
|
32 |
+
|
33 |
+
*.idea/
|
34 |
+
|
35 |
+
# PyInstaller
|
36 |
+
# Usually these files are written by a python script from a template
|
37 |
+
# before PyInstaller builds the exe, so as to inject date/other info into it.
|
38 |
+
*.manifest
|
39 |
+
*.spec
|
40 |
+
|
41 |
+
# Installer logs
|
42 |
+
pip-log.txt
|
43 |
+
pip-delete-this-directory.txt
|
44 |
+
|
45 |
+
# Unit test / coverage reports
|
46 |
+
htmlcov/
|
47 |
+
.tox/
|
48 |
+
.nox/
|
49 |
+
.coverage
|
50 |
+
.coverage.*
|
51 |
+
.cache
|
52 |
+
nosetests.xml
|
53 |
+
coverage.xml
|
54 |
+
*.cover
|
55 |
+
*.py,cover
|
56 |
+
.hypothesis/
|
57 |
+
.pytest_cache/
|
58 |
+
mlruns/
|
59 |
+
|
60 |
+
# Translations
|
61 |
+
*.mo
|
62 |
+
*.pot
|
63 |
+
|
64 |
+
# Django stuff:
|
65 |
+
*.log
|
66 |
+
local_settings.py
|
67 |
+
db.sqlite3
|
68 |
+
db.sqlite3-journal
|
69 |
+
|
70 |
+
# Flask stuff:
|
71 |
+
instance/
|
72 |
+
.webassets-cache
|
73 |
+
|
74 |
+
# Scrapy stuff:
|
75 |
+
.scrapy
|
76 |
+
|
77 |
+
# Sphinx documentation
|
78 |
+
docs/_build/
|
79 |
+
|
80 |
+
# PyBuilder
|
81 |
+
target/
|
82 |
+
|
83 |
+
# Jupyter Notebook
|
84 |
+
.ipynb_checkpoints
|
85 |
+
|
86 |
+
# IPython
|
87 |
+
profile_default/
|
88 |
+
ipython_config.py
|
89 |
+
|
90 |
+
# Profiling
|
91 |
+
*.pclprof
|
92 |
+
|
93 |
+
# pyenv
|
94 |
+
.python-version
|
95 |
+
|
96 |
+
# pipenv
|
97 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
98 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
99 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
100 |
+
# install all needed dependencies.
|
101 |
+
#Pipfile.lock
|
102 |
+
|
103 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
104 |
+
__pypackages__/
|
105 |
+
|
106 |
+
# Celery stuff
|
107 |
+
celerybeat-schedule
|
108 |
+
celerybeat.pid
|
109 |
+
|
110 |
+
# SageMath parsed files
|
111 |
+
*.sage.py
|
112 |
+
|
113 |
+
# Environments
|
114 |
+
.env
|
115 |
+
.venv
|
116 |
+
.idea
|
117 |
+
env/
|
118 |
+
venv/
|
119 |
+
ENV/
|
120 |
+
env.bak/
|
121 |
+
venv.bak/
|
122 |
+
|
123 |
+
# Spyder project settings
|
124 |
+
.spyderproject
|
125 |
+
.spyproject
|
126 |
+
|
127 |
+
# VSCode project settings
|
128 |
+
.vscode/
|
129 |
+
|
130 |
+
# Rope project settings
|
131 |
+
.ropeproject
|
132 |
+
|
133 |
+
# mkdocs documentation
|
134 |
+
/site
|
135 |
+
|
136 |
+
# mypy
|
137 |
+
.mypy_cache/
|
138 |
+
.dmypy.json
|
139 |
+
dmypy.json
|
140 |
+
|
141 |
+
# Pyre type checker
|
142 |
+
.pyre/
|
143 |
+
|
144 |
+
# datasets and projects (ignore /datasets dir at root only to allow for docs/en/datasets dir)
|
145 |
+
/datasets
|
146 |
+
runs/
|
147 |
+
wandb/
|
148 |
+
.DS_Store
|
149 |
+
|
150 |
+
# Neural Network weights -----------------------------------------------------------------------------------------------
|
151 |
+
weights/
|
152 |
+
*.weights
|
153 |
+
*.pt
|
154 |
+
*.pb
|
155 |
+
*.onnx
|
156 |
+
*.engine
|
157 |
+
*.mlmodel
|
158 |
+
*.mlpackage
|
159 |
+
*.torchscript
|
160 |
+
*.tflite
|
161 |
+
*.h5
|
162 |
+
*_saved_model/
|
163 |
+
*_web_model/
|
164 |
+
*_openvino_model/
|
165 |
+
*_paddle_model/
|
166 |
+
*_ncnn_model/
|
167 |
+
pnnx*
|
168 |
+
|
169 |
+
# Autogenerated files for tests
|
170 |
+
/ultralytics/assets/
|
171 |
+
|
172 |
+
# calibration image
|
173 |
+
calibration_*.npy
|
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import PIL.Image as Image
|
3 |
+
|
4 |
+
from ultralytics import ASSETS, YOLO
|
5 |
+
|
6 |
+
model = None
|
7 |
+
|
8 |
+
|
9 |
+
def predict_image(img, conf_threshold, iou_threshold, model_name):
|
10 |
+
"""Predicts objects in an image using a YOLOv8 model with adjustable confidence and IOU thresholds."""
|
11 |
+
model = YOLO(model_name)
|
12 |
+
results = model.predict(
|
13 |
+
source=img,
|
14 |
+
conf=conf_threshold,
|
15 |
+
iou=iou_threshold,
|
16 |
+
show_labels=True,
|
17 |
+
show_conf=True,
|
18 |
+
imgsz=640,
|
19 |
+
)
|
20 |
+
|
21 |
+
for r in results:
|
22 |
+
im_array = r.plot()
|
23 |
+
im = Image.fromarray(im_array[..., ::-1])
|
24 |
+
|
25 |
+
return im
|
26 |
+
|
27 |
+
|
28 |
+
iface = gr.Interface(
|
29 |
+
fn=predict_image,
|
30 |
+
inputs=[
|
31 |
+
gr.Image(type="pil", label="Upload Image"),
|
32 |
+
gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
|
33 |
+
gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
|
34 |
+
gr.Radio(choices=["yolo11n", "yolo11s", "yolo11m"], label="Model Name", value="yolo11n"),
|
35 |
+
],
|
36 |
+
outputs=gr.Image(type="pil", label="Result"),
|
37 |
+
title="Ultralytics Gradio Application π",
|
38 |
+
description="Upload images for inference. The Ultralytics YOLO11n model is used by default.",
|
39 |
+
examples=[
|
40 |
+
[ASSETS / "bus.jpg", 0.25, 0.45, "yolo11n.pt"],
|
41 |
+
[ASSETS / "zidane.jpg", 0.25, 0.45, "yolo11n.pt"],
|
42 |
+
],
|
43 |
+
)
|
44 |
+
iface.launch(share=True)
|