File size: 3,651 Bytes
fbd6723
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# Intel Image Classifier - Deployment Guide

## Overview

This application is a full-stack web classifier for natural scene images using two CNN models:
- **PyTorch Model**: Custom CNN architecture
- **TensorFlow Model**: Custom CNN architecture

The application combines:
- **Backend**: Django REST API
- **Frontend**: React with Material-UI
- **Models**: Two Deep Learning models for image classification

## Quick Start for Hugging Face Spaces

### Prerequisites

- Git
- Docker & Docker Compose (for local development)
- Or access to Hugging Face Spaces

### Option 1: Deploy to Hugging Face Spaces (Recommended)

1. **Fork/Clone the Repository**
   ```bash
   git clone https://github.com/danielle2035/Intel_classification.git
   cd Intel_classification
   ```

2. **Add Your Trained Models**
   
   Place your trained model files in the `backend/api/models/` directory:
   ```
   backend/api/models/
   ├── pytorch_model.pth      (PyTorch model)
   └── model_best.keras       (TensorFlow model)
   ```

3. **Push to Hugging Face**
   ```bash
   # Add HF as remote
   git remote add hf https://huggingface.co/spaces/YOUR_USERNAME/Intel_classification
   
   # Push to deploy
   git push hf main
   ```

4. **Access Your App**
   - Go to: `https://huggingface.co/spaces/YOUR_USERNAME/Intel_classification`
   - The app will build and deploy automatically!

### Option 2: Build and Run Locally

#### With Docker Compose (Separate Services)

```bash
docker-compose up --build
```

Services will be available at:
- Frontend: `http://localhost:3000`
- Backend API: `http://localhost:8000`
- API Docs: `http://localhost:8000/swagger`

#### With Docker (Unified Container - HF Mode)

```bash
docker build -t intel-classifier .
docker run -p 7860:7860 intel-classifier
```

Access at: `http://localhost:7860`

#### Without Docker (Development)

1. **Backend Setup**
   ```bash
   cd backend/api
   python -m venv venv
   source venv/bin/activate  # On Windows: venv\Scripts\activate
   pip install -r ../requirements.txt
   python manage.py migrate
   python manage.py runserver 0.0.0.0:8000
   ```

2. **Frontend Setup (separate terminal)**
   ```bash
   cd frontend
   npm install
   npm start
   ```

3. **Access**
   - Frontend: `http://localhost:3000`
   - Backend API: `http://localhost:8000`

## API Endpoints

### Classification

**POST** `/api/classify/`

Classify an image using either PyTorch or TensorFlow model.

**Response:**
```json
{
  "class": "mountain",
  "confidence": 0.95,
  "model_used": "pytorch",
  "probabilities": {
    "buildings": 0.02,
    "forest": 0.01,
    "glacier": 0.01,
    "mountain": 0.95,
    "sea": 0.01,
    "street": 0.00
  }
}
```

## Models & Classes

### Supported Classes
- buildings / Bâtiments / Kër yi
- forest / Forêt / Géej bu wees
- glacier / Glacier / Dëkk bu sedd
- mountain / Montagne / Tund bi
- sea / Mer / Géej bi
- street / Rue / Yoon bi

## Deployment Checklist

- [ ] Add trained models to `backend/api/models/`
- [ ] Update `ALLOWED_HOSTS` in settings if needed
- [ ] Test locally with Docker
- [ ] Push to Hugging Face Spaces
- [ ] Test on HF Space URL

## Troubleshooting

**Port Already in Use**
```bash
lsof -i :7860  # Find process
kill -9 <PID>   # Kill it
```

**Models Not Loading**
- Ensure files are in `backend/api/models/`
- Check file names: `pytorch_model.pth`, `model_best.keras`

**CORS Errors**
- Verify backend and frontend are accessible
- Check Django CSRF_TRUSTED_ORIGINS includes your HF URL

## Performance Tips

1. Resize images before upload (< 10MB)
2. PyTorch is generally faster on CPU
3. Adjust confidence threshold in `api_views.py` if needed