This is a beginner-friendly object detection project using:
- Python
- Streamlit
- Ultralytics YOLOv8
- YOLOv8n pretrained on the COCO dataset, which supports 80 common object classes
The app lets a user upload an image, click Detect Objects, and see:
- The original uploaded image
- A browser camera snapshot option
- The annotated image with bounding boxes, class labels, and confidence scores
- A table of detected objects
- Overall detection stats, including total objects found and the most common class
- Download buttons for the annotated image and detection table
.
|-- app.py
|-- .env.example
|-- .gitignore
|-- .streamlit/
| `-- config.toml
|-- requirements.txt
|-- runtime.txt
`-- README.md
Do not upload your local virtual environment folder to GitHub. The .gitignore
file already excludes .venv/, model weights, cache files, and local secrets.
- Streamlit creates a simple web interface.
- The user uploads an image or takes a camera snapshot.
- The app loads the pretrained
yolov8n.ptmodel from Ultralytics. - YOLOv8 detects objects in the uploaded image.
- The app displays the annotated image, detection table, and summary stats.
The first time you run the app, Ultralytics may download the yolov8n.pt model
file automatically. This file is ignored by Git because it can be downloaded
again when needed.
git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY-NAME.git
cd YOUR-REPOSITORY-NAMEIf you are working from this folder already, you can skip this step.
Windows PowerShell:
python -m venv .venv
.\.venv\Scripts\Activate.ps1If PowerShell blocks activation, run this command once, then try activating again:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUsermacOS or Linux:
python -m venv .venv
source .venv/bin/activatepip install -r requirements.txtstreamlit run app.pyThen open the local URL shown in the terminal, usually:
http://localhost:8501
Press Ctrl + C in the terminal.
To leave the virtual environment, run:
deactivateIf this folder is not a Git repository yet, run:
git init
git add .
git commit -m "Initial YOLOv8 Streamlit app"
git branch -M main
git remote add origin https://github.com/YOUR-USERNAME/YOUR-REPOSITORY-NAME.git
git push -u origin mainReplace YOUR-USERNAME and YOUR-REPOSITORY-NAME with your own GitHub details.
- Push this project to a GitHub repository.
- Go to Streamlit Community Cloud.
- Sign in with GitHub.
- Click New app.
- Select your repository.
- Set the main file path to:
app.py
- Click Deploy.
Streamlit Community Cloud will install the packages from requirements.txt automatically.
- This app uses
opencv-python-headlessinstead ofopencv-python, which is better for cloud deployment because it does not require desktop GUI libraries. - The confidence threshold slider controls how strict the model is. A lower value may show more detections, while a higher value shows only stronger predictions.
- The IoU threshold controls how much overlapping boxes are filtered.
- The inference image size controls the speed and detail tradeoff. Use
320or416for faster detection, and640or higher for better small-object detection. - YOLOv8n is the smallest YOLOv8 model. It is fast and works well for demos and lightweight deployments.
- Snapshot mode uses Streamlit's browser camera input and is the most reliable camera option for Streamlit Community Cloud.