CoolFace
Apppublic

johnwesley756/instance-segmentation

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
App README

🦷 Tooth Decay Detection and Severity Analysis Using Deep Learning

A computer vision project that uses YOLOv8 to detect dental conditions like tooth, caries, and cavity from images. The application features a FastAPI backend for API-based inference and a Streamlit frontend for interactive testing.


πŸ“Œ Features

  • β€”βš‘ Real-time detection of tooth, caries, and cavity
  • β€”πŸ“Š Severity classification (Tooth β†’ Caries β†’ Cavity)
  • β€”πŸ“ Natural language summary for each detection
  • β€”πŸ”Œ REST API for integration with other applications
  • β€”πŸŒ Streamlit UI for easy testing and visualization
  • β€”πŸ³ Docker support for easy deployment
  • β€”β˜οΈ Hugging Face Spaces ready

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Streamlit UI  β”‚ ──HTTP──▢│   FastAPI Server β”‚
β”‚   (Frontend)    β”‚         β”‚    (Backend)     β”‚
β”‚   Port: 7860    β”‚         β”‚    Port: 8000    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                     β”‚
                                     β–Ό
                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                            β”‚  YOLOv8 Model   β”‚
                            β”‚    (best.pt)    β”‚
                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”§ Technologies Used

  • β€”Python 3.11+
  • β€”YOLOv8 / Ultralytics - Object detection model
  • β€”FastAPI - REST API backend
  • β€”Streamlit - Interactive frontend
  • β€”OpenCV - Image processing
  • β€”Docker - Containerization

πŸ“ Project Structure

πŸ“¦ Instance-segmentation
 ┣ πŸ“œ api.py                 # FastAPI backend server
 ┣ πŸ“œ app.py                 # Streamlit frontend
 ┣ πŸ“œ train_model.py         # Original Streamlit app (legacy)
 ┣ πŸ“œ best.pt                # YOLOv8 trained model
 ┣ πŸ“œ requirements.txt       # Python dependencies
 ┣ πŸ“œ Dockerfile             # Docker configuration
 ┣ πŸ“œ start.sh               # Linux/Mac startup script
 ┣ πŸ“œ start.bat              # Windows startup script
 β”— πŸ“œ README.md              # This file

πŸš€ Quick Start

Option 1: Local Development

  1. 1.Install dependencies
bash
pip install -r requirements.txt
  1. 1.Start the FastAPI backend
bash
uvicorn api:app --host 0.0.0.0 --port 8000
  1. 1.Start the Streamlit frontend (in a new terminal)
bash
streamlit run app.py --server.port 7860
  1. 1.Access the application
  2. 2.Streamlit UI: http://localhost:7860
  3. 3.FastAPI Docs: http://localhost:8000/docs

Option 2: Using Startup Scripts

Windows:

bash
start.bat

Linux/Mac:

bash
chmod +x start.sh
./start.sh

Option 3: Docker

  1. 1.Build the Docker image
bash
docker build -t tooth-detection .
  1. 1.Run the container
bash
docker run -p 7860:7860 -p 8000:8000 tooth-detection

πŸ”Œ API Endpoints

GET /

Root endpoint with API information

GET /health

Health check endpoint

json
{
  "status": "healthy",
  "model_loaded": true,
  "model_path": "best.pt"
}

POST /predict

Upload an image for tooth decay detection

Request:

  • β€”Method: POST
  • β€”Content-Type: multipart/form-data
  • β€”Body: file (image file)

Response:

json
{
  "success": true,
  "severity": "Caries",
  "summary": "Caries (initial decay) detected...",
  "detections": [
    {
      "class": "caries",
      "confidence": 0.856,
      "bbox": [120.5, 45.2, 280.3, 190.7]
    }
  ],
  "total_detections": 1,
  "annotated_image": "base64_encoded_image..."
}

Example using cURL:

bash
curl -X POST "http://localhost:8000/predict" \
  -F "file=@dental_image.jpg"

Example using Python:

python
import requests

url = "http://localhost:8000/predict"
files = {"file": open("dental_image.jpg", "rb")}
response = requests.post(url, files=files)
print(response.json())

βœ… Severity Logic

Detected LabelsSeverity
Contains "cavity"Cavity
Else contains "caries"Caries
Only "tooth"Tooth
NoneNo Detection

🌐 Deploying to Hugging Face Spaces

  1. 1.Create a new Space on Hugging Face
  2. 2.Choose "Docker" as the SDK
  1. 1.Upload files:
  2. 2.api.py
  3. 3.app.py
  4. 4.best.pt
  5. 5.requirements.txt
  6. 6.Dockerfile
  7. 7.start.sh
  1. 1.The Space will automatically build and deploy
  1. 1.Access your deployed app at:
  2. 2.https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME

πŸ§ͺ Testing the Model

  1. 1.Upload a dental X-ray or intraoral image
  2. 2.The model will detect and classify:
  3. 3.Tooth: Healthy teeth
  4. 4.Caries: Early-stage decay
  5. 5.Cavity: Advanced decay
  6. 6.View the annotated image with bounding boxes
  7. 7.Read the severity level and summary

🧠 Future Enhancements

  • β€”Add authentication for API access
  • β€”Implement batch processing for multiple images
  • β€”Add model versioning and A/B testing
  • β€”Create mobile app using the API
  • β€”Add real-time webcam detection
  • β€”Integrate with dental clinic management systems

πŸ“„ License

This project is for educational and research purposes.


πŸ‘¨β€πŸ’» Developer

Built with ❀️ using YOLOv8, FastAPI, and Streamlit