Spaces:
Sleeping
Sleeping
| # Base image with Python | |
| FROM python:3.10-slim | |
| # Set working directory | |
| WORKDIR /app | |
| # Environment variables | |
| ENV PYTHONUNBUFFERED=1 | |
| ENV MODEL_DIR=/tmp/models/realvisxl_v4 | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| git \ | |
| wget \ | |
| curl \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Copy all project files | |
| COPY . /app | |
| # Create model directory | |
| RUN mkdir -p ${MODEL_DIR} | |
| # --- Install Python dependencies --- | |
| RUN pip install --no-cache-dir \ | |
| annotated-types==0.7.0 \ | |
| anyio==4.11.0 \ | |
| certifi==2025.10.5 \ | |
| click==8.3.0 \ | |
| colorama==0.4.6 \ | |
| fastapi==0.119.0 \ | |
| h11==0.16.0 \ | |
| httpcore==1.0.9 \ | |
| httpx==0.28.1 \ | |
| idna==3.11 \ | |
| pydantic==2.12.2 \ | |
| pydantic_core==2.41.4 \ | |
| python-dotenv==1.1.1 \ | |
| sniffio==1.3.1 \ | |
| starlette==0.48.0 \ | |
| typing_extensions==4.15.0 \ | |
| typing-inspection==0.4.2 \ | |
| uvicorn==0.37.0 \ | |
| torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu \ | |
| diffusers==0.30.3 \ | |
| huggingface_hub==0.26.2 \ | |
| accelerate==1.1.1 \ | |
| safetensors==0.4.5 \ | |
| pillow==10.4.0 | |
| # --- Pre-download model into /tmp/models/realvisxl_v4 --- | |
| RUN python -c "\ | |
| import torch; \ | |
| from diffusers import StableDiffusionXLPipeline; \ | |
| from pathlib import Path; \ | |
| model_dir = Path('${MODEL_DIR}'); \ | |
| if not model_dir.exists(): \ | |
| print('Downloading model...'); \ | |
| pipe = StableDiffusionXLPipeline.from_pretrained('SG161222/RealVisXL_V4.0', torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32); \ | |
| pipe.save_pretrained(model_dir); \ | |
| print('Model downloaded to', model_dir); \ | |
| else: \ | |
| print('Model already exists at', model_dir); \ | |
| " | |
| # Expose the app port | |
| EXPOSE 8000 | |
| # Command to run FastAPI server | |
| CMD ["uvicorn", "api.server:app", "--host", "0.0.0.0", "--port", "8000"] | |