Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YOLOv8 Object Detection Streamlit App

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

Project Files

.
|-- 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.

How It Works

  1. Streamlit creates a simple web interface.
  2. The user uploads an image or takes a camera snapshot.
  3. The app loads the pretrained yolov8n.pt model from Ultralytics.
  4. YOLOv8 detects objects in the uploaded image.
  5. 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.

Run Locally

1. Clone the project

git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY-NAME.git
cd YOUR-REPOSITORY-NAME

If you are working from this folder already, you can skip this step.

2. Create a virtual environment

Windows PowerShell:

python -m venv .venv
.\.venv\Scripts\Activate.ps1

If PowerShell blocks activation, run this command once, then try activating again:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

macOS or Linux:

python -m venv .venv
source .venv/bin/activate

3. Install dependencies

pip install -r requirements.txt

4. Start the Streamlit app

streamlit run app.py

Then open the local URL shown in the terminal, usually:

http://localhost:8501

5. Stop the app

Press Ctrl + C in the terminal.

To leave the virtual environment, run:

deactivate

Push to GitHub

If 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 main

Replace YOUR-USERNAME and YOUR-REPOSITORY-NAME with your own GitHub details.

Deploy to Streamlit Community Cloud

  1. Push this project to a GitHub repository.
  2. Go to Streamlit Community Cloud.
  3. Sign in with GitHub.
  4. Click New app.
  5. Select your repository.
  6. Set the main file path to:
app.py
  1. Click Deploy.

Streamlit Community Cloud will install the packages from requirements.txt automatically.

Notes

  • This app uses opencv-python-headless instead of opencv-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 320 or 416 for faster detection, and 640 or 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.

About

YOLOv8 object detection app built with Streamlit and Ultralytics.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages