Spaces:
Sleeping
Sleeping

Refactor Docker setup: remove Ollama integration, update FastAPI service, enhance health checks, and improve README documentation
2e94196
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:
- 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
# 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
# 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)
FASTAPI_PORT=7860
ENVIRONMENT=development
LOG_LEVEL=info
Custom Configuration
To modify ports or other settings:
- Edit
.env
file - Restart services:
docker-compose up -d
π§ Development
Building Images
# Build only FastAPI service
docker-compose build fastapi
# Build with no cache
docker-compose build --no-cache
Viewing Logs
# All services
docker-compose logs -f
# Specific service
docker-compose logs -f fastapi
Debugging
# 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
- Port conflicts: Change ports in
.env
file - Model loading fails: Check internet connection and available memory
- Application startup slow: Transformers models need time to download and load
Reset Everything
# 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:
# 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
curl -X POST "http://localhost:7860/analyze-image" \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "[email protected]"
Health Check
curl http://localhost:7860/health
π€ Contributing
- Make changes to the code
- Test with
docker-compose up --build
- Submit pull request
π License
This project is licensed under the MIT License.