Spaces:
Sleeping
Sleeping
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.
|