Spaces:
Running
Running
RizwanMunawar
commited on
Commit
·
8d18811
1
Parent(s):
11b166f
add gradio application code
Browse files- .gitignore +171 -0
- .idea/.gitignore +3 -0
- .idea/YOLOv8_Space.iml +8 -0
- .idea/inspectionProfiles/Project_Default.xml +36 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/material_theme_project_new.xml +10 -0
- .idea/misc.xml +7 -0
- .idea/modules.xml +8 -0
- .idea/vcs.xml +6 -0
- app.py +41 -0
.gitignore
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# PyInstaller
|
| 34 |
+
# Usually these files are written by a python script from a template
|
| 35 |
+
# before PyInstaller builds the exe, so as to inject date/other info into it.
|
| 36 |
+
*.manifest
|
| 37 |
+
*.spec
|
| 38 |
+
|
| 39 |
+
# Installer logs
|
| 40 |
+
pip-log.txt
|
| 41 |
+
pip-delete-this-directory.txt
|
| 42 |
+
|
| 43 |
+
# Unit test / coverage reports
|
| 44 |
+
htmlcov/
|
| 45 |
+
.tox/
|
| 46 |
+
.nox/
|
| 47 |
+
.coverage
|
| 48 |
+
.coverage.*
|
| 49 |
+
.cache
|
| 50 |
+
nosetests.xml
|
| 51 |
+
coverage.xml
|
| 52 |
+
*.cover
|
| 53 |
+
*.py,cover
|
| 54 |
+
.hypothesis/
|
| 55 |
+
.pytest_cache/
|
| 56 |
+
mlruns/
|
| 57 |
+
|
| 58 |
+
# Translations
|
| 59 |
+
*.mo
|
| 60 |
+
*.pot
|
| 61 |
+
|
| 62 |
+
# Django stuff:
|
| 63 |
+
*.log
|
| 64 |
+
local_settings.py
|
| 65 |
+
db.sqlite3
|
| 66 |
+
db.sqlite3-journal
|
| 67 |
+
|
| 68 |
+
# Flask stuff:
|
| 69 |
+
instance/
|
| 70 |
+
.webassets-cache
|
| 71 |
+
|
| 72 |
+
# Scrapy stuff:
|
| 73 |
+
.scrapy
|
| 74 |
+
|
| 75 |
+
# Sphinx documentation
|
| 76 |
+
docs/_build/
|
| 77 |
+
|
| 78 |
+
# PyBuilder
|
| 79 |
+
target/
|
| 80 |
+
|
| 81 |
+
# Jupyter Notebook
|
| 82 |
+
.ipynb_checkpoints
|
| 83 |
+
|
| 84 |
+
# IPython
|
| 85 |
+
profile_default/
|
| 86 |
+
ipython_config.py
|
| 87 |
+
|
| 88 |
+
# Profiling
|
| 89 |
+
*.pclprof
|
| 90 |
+
|
| 91 |
+
# pyenv
|
| 92 |
+
.python-version
|
| 93 |
+
|
| 94 |
+
# pipenv
|
| 95 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 96 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 97 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 98 |
+
# install all needed dependencies.
|
| 99 |
+
#Pipfile.lock
|
| 100 |
+
|
| 101 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
| 102 |
+
__pypackages__/
|
| 103 |
+
|
| 104 |
+
# Celery stuff
|
| 105 |
+
celerybeat-schedule
|
| 106 |
+
celerybeat.pid
|
| 107 |
+
|
| 108 |
+
# SageMath parsed files
|
| 109 |
+
*.sage.py
|
| 110 |
+
|
| 111 |
+
# Environments
|
| 112 |
+
.env
|
| 113 |
+
.venv
|
| 114 |
+
.idea
|
| 115 |
+
env/
|
| 116 |
+
venv/
|
| 117 |
+
ENV/
|
| 118 |
+
env.bak/
|
| 119 |
+
venv.bak/
|
| 120 |
+
|
| 121 |
+
# Spyder project settings
|
| 122 |
+
.spyderproject
|
| 123 |
+
.spyproject
|
| 124 |
+
|
| 125 |
+
# VSCode project settings
|
| 126 |
+
.vscode/
|
| 127 |
+
|
| 128 |
+
# Rope project settings
|
| 129 |
+
.ropeproject
|
| 130 |
+
|
| 131 |
+
# mkdocs documentation
|
| 132 |
+
/site
|
| 133 |
+
|
| 134 |
+
# mypy
|
| 135 |
+
.mypy_cache/
|
| 136 |
+
.dmypy.json
|
| 137 |
+
dmypy.json
|
| 138 |
+
|
| 139 |
+
# Pyre type checker
|
| 140 |
+
.pyre/
|
| 141 |
+
|
| 142 |
+
# datasets and projects (ignore /datasets dir at root only to allow for docs/en/datasets dir)
|
| 143 |
+
/datasets
|
| 144 |
+
runs/
|
| 145 |
+
wandb/
|
| 146 |
+
.DS_Store
|
| 147 |
+
|
| 148 |
+
# Neural Network weights -----------------------------------------------------------------------------------------------
|
| 149 |
+
weights/
|
| 150 |
+
*.weights
|
| 151 |
+
*.pt
|
| 152 |
+
*.pb
|
| 153 |
+
*.onnx
|
| 154 |
+
*.engine
|
| 155 |
+
*.mlmodel
|
| 156 |
+
*.mlpackage
|
| 157 |
+
*.torchscript
|
| 158 |
+
*.tflite
|
| 159 |
+
*.h5
|
| 160 |
+
*_saved_model/
|
| 161 |
+
*_web_model/
|
| 162 |
+
*_openvino_model/
|
| 163 |
+
*_paddle_model/
|
| 164 |
+
*_ncnn_model/
|
| 165 |
+
pnnx*
|
| 166 |
+
|
| 167 |
+
# Autogenerated files for tests
|
| 168 |
+
/ultralytics/assets/
|
| 169 |
+
|
| 170 |
+
# calibration image
|
| 171 |
+
calibration_*.npy
|
.idea/.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Default ignored files
|
| 2 |
+
/shelf/
|
| 3 |
+
/workspace.xml
|
.idea/YOLOv8_Space.iml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<module type="PYTHON_MODULE" version="4">
|
| 3 |
+
<component name="NewModuleRootManager">
|
| 4 |
+
<content url="file://$MODULE_DIR$" />
|
| 5 |
+
<orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" />
|
| 6 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
| 7 |
+
</component>
|
| 8 |
+
</module>
|
.idea/inspectionProfiles/Project_Default.xml
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<component name="InspectionProjectProfileManager">
|
| 2 |
+
<profile version="1.0">
|
| 3 |
+
<option name="myName" value="Project Default" />
|
| 4 |
+
<inspection_tool class="PyAttributeOutsideInitInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
| 5 |
+
<inspection_tool class="PyGlobalUndefinedInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
| 6 |
+
<inspection_tool class="PyMethodMayBeStaticInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
| 7 |
+
<inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
| 8 |
+
<option name="ignoredErrors">
|
| 9 |
+
<list>
|
| 10 |
+
<option value="E501" />
|
| 11 |
+
<option value="E225" />
|
| 12 |
+
<option value="E402" />
|
| 13 |
+
<option value="E303" />
|
| 14 |
+
</list>
|
| 15 |
+
</option>
|
| 16 |
+
</inspection_tool>
|
| 17 |
+
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
| 18 |
+
<option name="ignoredErrors">
|
| 19 |
+
<list>
|
| 20 |
+
<option value="N803" />
|
| 21 |
+
<option value="N806" />
|
| 22 |
+
<option value="N813" />
|
| 23 |
+
</list>
|
| 24 |
+
</option>
|
| 25 |
+
</inspection_tool>
|
| 26 |
+
<inspection_tool class="PyProtectedMemberInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
| 27 |
+
<inspection_tool class="PyShadowingNamesInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
| 28 |
+
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="false" level="WARNING" enabled_by_default="false">
|
| 29 |
+
<option name="ignoredIdentifiers">
|
| 30 |
+
<list>
|
| 31 |
+
<option value="app.*" />
|
| 32 |
+
</list>
|
| 33 |
+
</option>
|
| 34 |
+
</inspection_tool>
|
| 35 |
+
</profile>
|
| 36 |
+
</component>
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<component name="InspectionProjectProfileManager">
|
| 2 |
+
<settings>
|
| 3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
| 4 |
+
<version value="1.0" />
|
| 5 |
+
</settings>
|
| 6 |
+
</component>
|
.idea/material_theme_project_new.xml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="MaterialThemeProjectNewConfig">
|
| 4 |
+
<option name="metadata">
|
| 5 |
+
<MTProjectMetadataState>
|
| 6 |
+
<option name="userId" value="-2b002206:1923c9238b0:-7fe2" />
|
| 7 |
+
</MTProjectMetadataState>
|
| 8 |
+
</option>
|
| 9 |
+
</component>
|
| 10 |
+
</project>
|
.idea/misc.xml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="Black">
|
| 4 |
+
<option name="sdkName" value="Python 3.9" />
|
| 5 |
+
</component>
|
| 6 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
|
| 7 |
+
</project>
|
.idea/modules.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="ProjectModuleManager">
|
| 4 |
+
<modules>
|
| 5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/YOLOv8_Space.iml" filepath="$PROJECT_DIR$/.idea/YOLOv8_Space.iml" />
|
| 6 |
+
</modules>
|
| 7 |
+
</component>
|
| 8 |
+
</project>
|
.idea/vcs.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="VcsDirectoryMappings">
|
| 4 |
+
<mapping directory="" vcs="Git" />
|
| 5 |
+
</component>
|
| 6 |
+
</project>
|
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import PIL.Image as Image
|
| 3 |
+
|
| 4 |
+
from ultralytics import ASSETS, YOLO
|
| 5 |
+
|
| 6 |
+
model = YOLO("yolov8n.pt")
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def predict_image(img, conf_threshold, iou_threshold):
|
| 10 |
+
"""Predicts objects in an image using a YOLOv8 model with adjustable confidence and IOU thresholds."""
|
| 11 |
+
results = model.predict(
|
| 12 |
+
source=img,
|
| 13 |
+
conf=conf_threshold,
|
| 14 |
+
iou=iou_threshold,
|
| 15 |
+
show_labels=True,
|
| 16 |
+
show_conf=True,
|
| 17 |
+
imgsz=640,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
for r in results:
|
| 21 |
+
im_array = r.plot()
|
| 22 |
+
im = Image.fromarray(im_array[..., ::-1])
|
| 23 |
+
|
| 24 |
+
return im
|
| 25 |
+
|
| 26 |
+
iface = gr.Interface(
|
| 27 |
+
fn=predict_image,
|
| 28 |
+
inputs=[
|
| 29 |
+
gr.Image(type="pil", label="Upload Image"),
|
| 30 |
+
gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
|
| 31 |
+
gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
|
| 32 |
+
],
|
| 33 |
+
outputs=gr.Image(type="pil", label="Result"),
|
| 34 |
+
title="Ultralytics Gradio",
|
| 35 |
+
description="Upload images for inference. The Ultralytics YOLOv8n model is used by default.",
|
| 36 |
+
examples=[
|
| 37 |
+
[ASSETS / "bus.jpg", 0.25, 0.45],
|
| 38 |
+
[ASSETS / "zidane.jpg", 0.25, 0.45],
|
| 39 |
+
],
|
| 40 |
+
)
|
| 41 |
+
iface.launch()
|