CoolFace
Apppublic

johnwesley756/instance-segmentation

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
README.md248 linesDownload Raw Back to root
1---2title: Tooth Decay Detection & Severity Analysis3emoji: 🦷4colorFrom: blue5colorTo: purple6sdk: docker7sdk_version: "4.36.0"8app_file: app.py9pinned: false10---11 12# 🦷 Tooth Decay Detection and Severity Analysis Using Deep Learning13 14A 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.15 16---17 18## πŸ“Œ Features19 20* ⚑ Real-time detection of **tooth**, **caries**, and **cavity**21* πŸ“Š Severity classification (Tooth β†’ Caries β†’ Cavity)22* πŸ“ Natural language summary for each detection23* πŸ”Œ **REST API** for integration with other applications24* 🌐 **Streamlit UI** for easy testing and visualization25* 🐳 **Docker support** for easy deployment26* ☁️ **Hugging Face Spaces** ready27 28---29 30## πŸ—οΈ Architecture31 32```33β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”34β”‚   Streamlit UI  β”‚ ──HTTP──▢│   FastAPI Server β”‚35β”‚   (Frontend)    β”‚         β”‚    (Backend)     β”‚36β”‚   Port: 7860    β”‚         β”‚    Port: 8000    β”‚37β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜38                                     β”‚39                                     β–Ό40                            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”41                            β”‚  YOLOv8 Model   β”‚42                            β”‚    (best.pt)    β”‚43                            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜44```45 46---47 48## πŸ”§ Technologies Used49 50* **Python 3.11+**51* **YOLOv8 / Ultralytics** - Object detection model52* **FastAPI** - REST API backend53* **Streamlit** - Interactive frontend54* **OpenCV** - Image processing55* **Docker** - Containerization56 57---58 59## πŸ“ Project Structure60 61```62πŸ“¦ Instance-segmentation63 ┣ πŸ“œ api.py                 # FastAPI backend server64 ┣ πŸ“œ app.py                 # Streamlit frontend65 ┣ πŸ“œ train_model.py         # Original Streamlit app (legacy)66 ┣ πŸ“œ best.pt                # YOLOv8 trained model67 ┣ πŸ“œ requirements.txt       # Python dependencies68 ┣ πŸ“œ Dockerfile             # Docker configuration69 ┣ πŸ“œ start.sh               # Linux/Mac startup script70 ┣ πŸ“œ start.bat              # Windows startup script71 β”— πŸ“œ README.md              # This file72```73 74---75 76## πŸš€ Quick Start77 78### Option 1: Local Development79 801. **Install dependencies**81```bash82pip install -r requirements.txt83```84 852. **Start the FastAPI backend**86```bash87uvicorn api:app --host 0.0.0.0 --port 800088```89 903. **Start the Streamlit frontend** (in a new terminal)91```bash92streamlit run app.py --server.port 786093```94 954. **Access the application**96   - Streamlit UI: http://localhost:786097   - FastAPI Docs: http://localhost:8000/docs98 99### Option 2: Using Startup Scripts100 101**Windows:**102```bash103start.bat104```105 106**Linux/Mac:**107```bash108chmod +x start.sh109./start.sh110```111 112### Option 3: Docker113 1141. **Build the Docker image**115```bash116docker build -t tooth-detection .117```118 1192. **Run the container**120```bash121docker run -p 7860:7860 -p 8000:8000 tooth-detection122```123 124---125 126## πŸ”Œ API Endpoints127 128### `GET /`129Root endpoint with API information130 131### `GET /health`132Health check endpoint133```json134{135  "status": "healthy",136  "model_loaded": true,137  "model_path": "best.pt"138}139```140 141### `POST /predict`142Upload an image for tooth decay detection143 144**Request:**145- Method: `POST`146- Content-Type: `multipart/form-data`147- Body: `file` (image file)148 149**Response:**150```json151{152  "success": true,153  "severity": "Caries",154  "summary": "Caries (initial decay) detected...",155  "detections": [156    {157      "class": "caries",158      "confidence": 0.856,159      "bbox": [120.5, 45.2, 280.3, 190.7]160    }161  ],162  "total_detections": 1,163  "annotated_image": "base64_encoded_image..."164}165```166 167**Example using cURL:**168```bash169curl -X POST "http://localhost:8000/predict" \170  -F "file=@dental_image.jpg"171```172 173**Example using Python:**174```python175import requests176 177url = "http://localhost:8000/predict"178files = {"file": open("dental_image.jpg", "rb")}179response = requests.post(url, files=files)180print(response.json())181```182 183---184 185## βœ… Severity Logic186 187| Detected Labels        | Severity     |188| ---------------------- | ------------ |189| Contains "cavity"      | Cavity       |190| Else contains "caries" | Caries       |191| Only "tooth"           | Tooth        |192| None                   | No Detection |193 194---195 196## 🌐 Deploying to Hugging Face Spaces197 1981. **Create a new Space** on [Hugging Face](https://huggingface.co/spaces)199   - Choose "Docker" as the SDK200 2012. **Upload files:**202   - `api.py`203   - `app.py`204   - `best.pt`205   - `requirements.txt`206   - `Dockerfile`207   - `start.sh`208 2093. **The Space will automatically build and deploy**210 2114. **Access your deployed app** at:212   - `https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME`213 214---215 216## πŸ§ͺ Testing the Model217 2181. Upload a dental X-ray or intraoral image2192. The model will detect and classify:220   - **Tooth**: Healthy teeth221   - **Caries**: Early-stage decay222   - **Cavity**: Advanced decay2233. View the annotated image with bounding boxes2244. Read the severity level and summary225 226---227 228## 🧠 Future Enhancements229 230* Add authentication for API access231* Implement batch processing for multiple images232* Add model versioning and A/B testing233* Create mobile app using the API234* Add real-time webcam detection235* Integrate with dental clinic management systems236 237---238 239## πŸ“„ License240 241This project is for educational and research purposes.242 243---244 245## πŸ‘¨β€πŸ’» Developer246 247Built with ❀️ using YOLOv8, FastAPI, and Streamlit248