File size: 3,964 Bytes
d2ba52b
 
2e94196
d2ba52b
 
 
2e94196
d2ba52b
2e94196
d2ba52b
 
 
2e94196
d2ba52b
 
 
2e94196
d2ba52b
 
 
 
2e94196
d2ba52b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2e94196
d2ba52b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2e94196
 
d2ba52b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2e94196
d2ba52b
2e94196
d2ba52b
 
 
 
 
 
2e94196
 
d2ba52b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# Fashion Analyzer - Docker Compose Setup

This project provides a secure, containerized fashion analysis application using Hugging Face Transformers and FastAPI with Docker Compose.

## πŸ—οΈ Architecture

The application consists of a single service:

1. **FastAPI Service**: Provides the web API and user interface with integrated Hugging Face transformers models for fashion analysis

## πŸ”’ Security Features

- βœ… **Pinned Python version** (3.11-slim) - Secure base image
- βœ… **Non-root user execution** - Enhanced container security
- βœ… **Security updates** - Latest package updates applied
- βœ… **Health checks** - Service monitoring and restart policies
- βœ… **Minimal dependencies** - Reduced attack surface

## πŸš€ Quick Start

### Prerequisites

- Docker Engine 20.10+
- Docker Compose 2.0+

### 1. Start the Application

```bash
# Start all services
docker-compose up -d

# View logs
docker-compose logs -f

# Check service status
docker-compose ps
```

### 2. Access the Application

- **Web Interface**: http://localhost:7860
- **API Documentation**: http://localhost:7860/docs
- **Health Check**: http://localhost:7860/health

### 3. Stop the Application

```bash
# Stop all services
docker-compose down

# Stop and remove volumes (removes logs)
docker-compose down -v
```

## πŸ“ Project Structure

```
AI/
β”œβ”€β”€ docker-compose.yml      # Main orchestration file
β”œβ”€β”€ Dockerfile.fastapi      # FastAPI service Dockerfile
β”œβ”€β”€ .env                    # Environment variables
β”œβ”€β”€ .dockerignore          # Docker build exclusions
β”œβ”€β”€ fast.py                # FastAPI application
β”œβ”€β”€ requirements.txt       # Python dependencies
└── logs/                  # Application logs (created at runtime)
```

## βš™οΈ Configuration

### Environment Variables (.env)

```env
FASTAPI_PORT=7860
ENVIRONMENT=development
LOG_LEVEL=info
```

### Custom Configuration

To modify ports or other settings:

1. Edit `.env` file
2. Restart services: `docker-compose up -d`

## πŸ”§ Development

### Building Images

```bash
# Build only FastAPI service
docker-compose build fastapi

# Build with no cache
docker-compose build --no-cache
```

### Viewing Logs

```bash
# All services
docker-compose logs -f

# Specific service
docker-compose logs -f fastapi
```

### Debugging

```bash
# Execute commands in running containers
docker-compose exec fastapi bash

# Check service health
docker-compose exec fastapi curl http://localhost:7860/health
```

## πŸ“Š Monitoring

### Health Checks

The FastAPI service includes health checks:

- **FastAPI**: Checks application health and model availability

## πŸ› οΈ Troubleshooting

### Common Issues

1. **Port conflicts**: Change ports in `.env` file
2. **Model loading fails**: Check internet connection and available memory
3. **Application startup slow**: Transformers models need time to download and load

### Reset Everything

```bash
# Stop and remove everything
docker-compose down -v --remove-orphans

# Remove images
docker-compose down --rmi all

# Start fresh
docker-compose up -d
```

## πŸ“ˆ Scaling

To run multiple FastAPI instances:

```bash
# Scale FastAPI service
docker-compose up -d --scale fastapi=3
```

Note: You'll need a load balancer for multiple instances.

## πŸ” Security Considerations

- Services run as non-root users
- Network isolation between services
- No sensitive data in environment variables
- Regular security updates applied
- Pinned dependency versions

## πŸ“ API Usage

### Upload and Analyze Image

```bash
curl -X POST "http://localhost:7860/analyze-image" \
     -H "accept: application/json" \
     -H "Content-Type: multipart/form-data" \
     -F "[email protected]"
```

### Health Check

```bash
curl http://localhost:7860/health
```

## 🀝 Contributing

1. Make changes to the code
2. Test with `docker-compose up --build`
3. Submit pull request

## πŸ“„ License

This project is licensed under the MIT License.