Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Version control
.git
.gitignore

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
venv/
ENV/
test_env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# IDE
.idea/
.vscode/
*.swp
*.swo

# Testing
.coverage
.pytest_cache/
htmlcov/
.tox/
.nox/
coverage.xml
*.cover
*.py,cover
.hypothesis/
test/

# Generated files
*.png
out/
generated/

# Docker
Dockerfile
docker-compose.yml
.dockerignore

# Documentation
README.md
LICENSE
*.md

# MLX and model files (will be downloaded at runtime)
*.safetensors
*.bin
*.pt
*.ckpt
.cache/
51 changes: 51 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Docker Image CI

on:
push:
branches: [ "main" ]
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "main" ]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
type=raw,value=latest,enable={{is_default_branch}}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM python:3.11-slim

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
&& rm -rf /var/lib/apt/lists/*

# Copy requirements first for better caching
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application
COPY . .

# Expose the port
EXPOSE 7860

# Set environment variables
ENV PORT=7860
ENV HOST=0.0.0.0

# Run the application
CMD ["python3.11", "flux_app.py", "--listen-all", "--port", "7860"]
109 changes: 109 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,121 @@ Parameters:

## Installation

### Method 1: Traditional Installation

```bash
python3.11 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```

### Method 2: Docker Installation 🐳

You can run Flux Generator using Docker in two ways:

#### Option A: Using Pre-built Image (Recommended)

The easiest way to run Flux Generator is using our pre-built Docker image:

```bash
# Pull and run the container
docker run -d \
-p 7860:7860 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
-e HF_HUB_ENABLE_HF_TRANSFER=1 \
--device /dev/apple_gpu_control \
--name flux-generator \
--restart always \
ghcr.io/yourusername/flux-generator:latest
```

#### Option B: Building Locally

If you prefer to build the image locally:

1. **Clone the repository:**
```bash
git clone https://github.com/yourusername/flux-generator.git
cd flux-generator
```

2. **Build and run using docker-compose:**
```bash
docker compose up -d
```
This will:
- Build the Docker image
- Start the container in the background
- Map port 7860 to your host
- Mount HuggingFace cache for model persistence
- Enable GPU access for Apple Silicon

3. **Access the UI:**
- Open your browser and navigate to: `http://localhost:7860`
- The UI and API will be available at this address

4. **View logs:**
```bash
docker compose logs -f
```

5. **Stop the container:**
```bash
docker compose down
```

### Docker Integration with Open WebUI

Both Flux Generator and Open WebUI can be run using pre-built Docker images:

```bash
# 1. Start Flux Generator
docker run -d \
-p 7860:7860 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
-e HF_HUB_ENABLE_HF_TRANSFER=1 \
--device /dev/apple_gpu_control \
--name flux-generator \
--restart always \
ghcr.io/yourusername/flux-generator:latest

# 2. Run Open WebUI
docker run -d \
-p 3000:8080 \
--add-host=host.docker.internal:host-gateway \
-e AUTOMATIC1111_BASE_URL=http://host.docker.internal:7860/ \
-e ENABLE_IMAGE_GENERATION=True \
-v open-webui:/app/backend/data \
--name open-webui \
--restart always \
ghcr.io/open-webui/open-webui:main
```

The connection flow works like this:
```
Open WebUI Container (3000) -> Flux Generator Container (7860)
```

### Testing Docker Setup

A test script is provided to verify the Docker installation:

```bash
# Make the script executable
chmod +x test_docker.sh

# Run the tests
./test_docker.sh
```

The test script will:
- Verify Docker installation
- Check for existing model files
- Test container setup
- Test API endpoints
- Generate a test image
- Clean up after testing

## Usage

Run the unified server with both UI and API:
Expand Down
19 changes: 19 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3.8'

services:
flux-generator:
build: .
ports:
- "7860:7860"
volumes:
- ~/.cache/huggingface:/root/.cache/huggingface
environment:
- HF_HUB_ENABLE_HF_TRANSFER=1
deploy:
resources:
reservations:
devices:
- driver: apple
count: all
capabilities: [gpu]
restart: unless-stopped
Loading