### Verify Installation of Key Libraries (Python) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/SETUP.md Runs Python commands to check the installed versions of PyTorch, Gradio, and Diffusers, and confirms that quantization support is available. This verifies that the installation was successful. ```python python -c "import torch; print(f'PyTorch: {torch.__version__}')" python -c "import gradio; print(f'Gradio: {gradio.__version__}')" python -c "import diffusers; print(f'Diffusers: {diffusers.__version__}')" python -c "from optimum.quanto import qint8; print('Quantization: OK')" ``` -------------------------------- ### Start FluxForge Studio with Public Sharing (Bash) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/SETUP.md This command starts the FluxForge Studio application and enables public sharing, allowing others to access the application. It requires Python and the main.py script. The output is the running application with a shareable link. ```bash python main.py --share ``` -------------------------------- ### Start FluxForge Studio Application (Bash) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/SETUP.md Launches the FluxForge Studio application by running the main Python script. Optional flags like '--share' or '-s' can be used to enable public sharing of the Gradio interface. ```bash python main.py For public sharing with authentication: python main.py --share # or python main.py -s ``` -------------------------------- ### Install Project Dependencies (Bash) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/SETUP.md Installs all required Python packages listed in the 'requirements.txt' file using pip. This includes core libraries like diffusers, optimum, torch, gradio, and transformers. ```bash pip install -r requirements.txt ``` -------------------------------- ### LoRA Configuration Example (JSON) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/SETUP.md An example JSON structure for configuring LoRA models. It specifies the file name, a description, and an activation keyword for each LoRA model to be used. ```json [ { "file_name": "example_lora.safetensors", "description": "Example LoRA description", "activation_keyword": "trigger_word" } ] ``` -------------------------------- ### Install Ollama Models (Bash) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/SETUP.md Downloads various AI models using the Ollama command-line tool. This includes text-only models like Llama3.2 and Mistral, as well as vision models for image analysis. ```bash # Text-only models ollama pull llama3.2 ollama pull mistral # Vision models for image analysis ollama pull llama3.2-vision ollama pull bakllava # Verify installation ollama list ``` -------------------------------- ### Clone FluxForge Studio Repository (Bash) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/SETUP.md Clones the FluxForge Studio repository from GitHub and navigates into the project directory. This is the first step in setting up the project locally. ```bash git clone https://github.com/VincentGourbin/FluxForge-Studio.git cd FluxForge-Studio ``` -------------------------------- ### Unified Negative Prompts Example (Text) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/FLUX2_MIGRATION_GUIDE.md Illustrates the use of negative prompts across all generation modes in FLUX.2. This helps in refining the output by specifying undesirable elements. ```text Negative Prompt: "blurry, low quality, distorted, watermark" ``` -------------------------------- ### Device Compatibility Console Output (Example) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/QUANTIZATION.md Example console output indicating that quantization is currently only available for FLUX Schnell and Dev models. ```text ⚠️ Quantification disponible pour FLUX Schnell et Dev uniquement ``` -------------------------------- ### Check FluxForge Studio Dependencies (Python) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/SETUP.md This command verifies if the core dependencies for FluxForge Studio, including torch, gradio, and diffusers, are installed and importable. It's a quick check to ensure the environment is set up correctly. The output is 'OK' if all libraries are found. ```python python -c "import torch, gradio, diffusers; print('OK')" ``` -------------------------------- ### Multi-Reference Mode Example (Python) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/FLUX2_MIGRATION_GUIDE.md Demonstrates the conceptual usage of multiple reference images for guiding image generation in FLUX.2. This feature allows blending styles and compositions from different input images. ```python # Example: Blend style from image 1 with composition from image 2 Reference 1: Style reference (e.g., oil painting) Reference 2: Composition reference (e.g., landscape layout) Reference 3: Optional detail reference ``` -------------------------------- ### Create and Activate Virtual Environment (Bash) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/SETUP.md Creates a Python virtual environment using 'venv' and then activates it. This isolates project dependencies. Activation commands differ for Windows and macOS/Linux. ```bash # Using venv python -m venv venv # Activate (Windows) venv\Scripts\activate # Activate (macOS/Linux) source venv/bin/activate ``` -------------------------------- ### Test Quantization with Optimum (Python) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/SETUP.md This command tests the quantization functionality using the optimum.quanto library, specifically checking for qint8 support. It's useful for verifying cross-platform quantization capabilities. The output is 'Quantization OK' if the quantization module is accessible. ```python python -c "from optimum.quanto import qint8; print('Quantization OK')" ``` -------------------------------- ### Update Project Dependencies Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/SETUP.md Upgrade all project dependencies listed in the `requirements.txt` file to their latest compatible versions. This ensures the project is using the most recent and potentially stable versions of its libraries. ```bash pip install --upgrade -r requirements.txt ``` -------------------------------- ### Unsupported Quantization Console Output (Example) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/QUANTIZATION.md Example console output warning about unsupported 4-bit quantization on a specific device, advising the user to use '8-bit' for substantial memory savings. ```text ⚠️ Quantification 4-bit non supportée sur [device] (tests montrent erreurs) 💡 Conseil: Utilisez '8-bit' pour économie mémoire substantielle ``` -------------------------------- ### Quantization Success Console Output (Example) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/QUANTIZATION.md Example console output indicating successful application of qint8 quantization for a FLUX Schnell model, estimating significant memory savings. ```text 🔧 Application quantification qint8 FLUX Schnell (économie mémoire ~70%) ✅ Quantification réussie: qint8 appliquée avec succès 💾 Économie mémoire estimée: ~70% ``` -------------------------------- ### Launch FluxForge Studio Application (Bash) Source: https://context7.com/vincentgourbin/fluxforge-studio/llms.txt Starts the FluxForge Studio web interface. Can be run locally or with public sharing enabled using the '--share' or '-s' flag. Public sharing includes authentication credentials. ```bash # Local access (default) python main.py # Access at: http://localhost:7860 # Public sharing with authentication python main.py --share # Output: 🌐 Creating public shareable link... # 🔐 Authentication credentials: # Username: a7b2c9d1 # Password: xK#9mP$2qR@5 # 📋 Share link will be displayed once the app starts... # With short flag python main.py -s ``` -------------------------------- ### LoRA Management Interface Setup Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/architecture.md Demonstrates how to integrate LoRA management into the application. This involves using predefined functions to create and set up event handlers for the LoRA manager interface, ensuring consistent user experience across different tools. ```python from src.ui.lora_manager import create_lora_manager_interface, setup_lora_events # ... in your UI setup code ... lora_manager_widget = create_lora_manager_interface() setup_lora_events(lora_manager_widget) ``` -------------------------------- ### Backup SQLite Database Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/SETUP.md Create a backup copy of the `generated_images.db` SQLite database. This is a crucial step for data safety and disaster recovery, ensuring that generated image data is not lost. ```bash # Backup database cp generated_images.db generated_images.db.backup ``` -------------------------------- ### Configure Environment Variables for FluxForge Studio Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/SETUP.md Set environment variables to optimize performance and configure network access for FluxForge Studio. This includes settings for MPS fallback on Apple Silicon, CUDA device visibility, and Gradio server name and port. ```bash # Apple Silicon optimization export PYTORCH_ENABLE_MPS_FALLBACK=1 # CUDA configuration export CUDA_VISIBLE_DEVICES=0 # Gradio configuration export GRADIO_SERVER_NAME="0.0.0.0" export GRADIO_SERVER_PORT=7860 ``` -------------------------------- ### Install and Configure Ollama for Prompt Enhancement Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/README.md Instructions for installing Ollama and pulling specific language models (llama3.2-vision and llama3.2) required for the AI-powered prompt enhancement feature. Ollama allows for local LLM integration to optimize prompts. ```bash # Install Ollama from https://ollama.ai/ ollama pull llama3.2-vision ollama pull llama3.2 ``` -------------------------------- ### Quantization Failure Console Output (Example) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/QUANTIZATION.md Example console output showing a failed qint8 quantization attempt, with a message indicating that the process will continue without quantization. ```text ⚠️ Quantification qint8 échouée: [error message] 🔄 Continuons sans quantification... ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/README.md This snippet demonstrates how to clone the FluxForge Studio repository from GitHub and install the necessary Python dependencies using pip. It highlights the use of the 'requirements.txt' file for managing dependencies, including specific versions of libraries like 'diffusers' for advanced features. ```bash git clone https://github.com/VincentGourbin/FluxForge-Studio.git cd FluxForge-Studio pip install -r requirements.txt ``` -------------------------------- ### Monitor GPU Usage with nvidia-smi Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/SETUP.md The `nvidia-smi` command-line utility provides real-time information about NVIDIA GPU utilization, memory usage, temperature, and more. It's essential for diagnosing performance issues and monitoring resource allocation. ```bash # NVIDIA nvidia-smi ``` -------------------------------- ### Monitor System Memory Usage Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/SETUP.md Use `free -h` on Linux or `top` on macOS/Linux to monitor system memory usage. This helps in identifying memory leaks or understanding overall system resource consumption. ```bash # System memory free -h # Linux top # macOS/Linux ``` -------------------------------- ### Enable External Access for Gradio Server Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/SETUP.md Modify launch parameters in `main.py` to allow external network access to the Gradio server. This involves setting `server_name` to '0.0.0.0' and optionally configuring `share` for a public Gradio URL. ```python demo.queue().launch( server_name="0.0.0.0", # Allow external access server_port=7860, share=False # Set to True for gradio.live URL ) ``` -------------------------------- ### New Metadata Fields for FLUX.2 Generations (JSON) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/FLUX2_MIGRATION_GUIDE.md Example JSON structure showing the new metadata fields added to database records for FLUX.2 generations. These fields track the FLUX.2 mode, migration details, and model alias. ```json { "flux2_mode": "inpainting", "migrated_from": "flux_fill", "migration_date": "2025-12-07T11:47:57", "model_alias": "flux2-dev" } ``` -------------------------------- ### Troubleshoot LoRA Loading (Bash) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/FLUX2_MIGRATION_GUIDE.md Provides Bash commands for troubleshooting LoRA loading issues. Solution 1 shows how to verify LoRA file size and format using `ls -lh`. Solution 2 suggests testing with a single LoRA by disabling others. ```bash # Check LoRA file size and format ls -lh lora/your_lora.safetensors ``` -------------------------------- ### Instantiate and Use FLUX.2 Generator (Python) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/FLUX2_CHANGELOG.md Demonstrates how to get an instance of the FLUX.2 generator and use its 'generate' method with various parameters. This includes prompt, mode, LoRA paths, and quantization settings. ```python # Generator from generator.flux2_generator import get_flux2_generator flux2_gen = get_flux2_generator() result = flux2_gen.generate( prompt="...", mode="text-to-image", negative_prompt="...", steps=28, guidance_scale=4.0, width=1024, height=1024, seed=0, lora_paths=["lora/style.safetensors"], lora_scales=[0.8], quantization="4-bit (BNB)" ) ``` -------------------------------- ### Start FluxForge Studio Application Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/README.md This snippet shows how to run the FluxForge Studio application using a Python script. It covers both local access via 'http://localhost:7860' and public sharing options using command-line arguments like '--share' or '-s', which generate temporary public links and credentials. ```bash python main.py python main.py --share python main.py -s ``` -------------------------------- ### Troubleshoot Out of Memory Error (Python) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/FLUX2_MIGRATION_GUIDE.md Provides Python code snippets for addressing 'Out of Memory' errors. Solution 1 suggests using quantization ('4-bit (BNB)' or '8-bit (Quanto)'). Solution 2 demonstrates reducing image resolution by setting width and height to 512. ```python quantization = "4-bit (BNB)" # or "8-bit (Quanto)" ``` ```python width = 512 # Instead of 1024 height = 512 ``` -------------------------------- ### Prepare Training JSON and Start LoRA Training (Python) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/API.md Orchestrates the complete LoRA training process by preparing the necessary JSON configuration and initiating the training job. It accepts numerous parameters defining the training data, hyperparameters, and output settings. ```python def prepare_training_json_and_start( files: List[str], descriptions: List[str], seed: int, steps: int, guidance: float, quantize: str, width: int, height: int, num_epochs: int, batch_size: int, plot_frequency: int, generate_image_frequency: int, validation_prompt: str, pdf_output: gr.Files, zip_output: gr.Files ) -> str: ``` -------------------------------- ### Rollback Procedure: Restore Code and Database (Bash) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/FLUX2_MIGRATION_GUIDE.md Bash commands to restore the application to a previous state. It includes copying backup files for `main.py` and the database (`generated_images.db`). ```bash # Restore main.py cp main.py.backup_before_flux2 main.py # Restore database cp generated_images.db.backup_20251207_114757 generated_images.db ``` -------------------------------- ### Configure Quanto 8-bit Quantization (Python) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/FLUX2_MIGRATION_GUIDE.md Sets the quantization to '8-bit (Quanto)' as a fallback option, particularly for Apple Silicon (MPS) where BNB might fail. This configuration uses the black-forest-labs/FLUX.2-dev model with runtime quantization, requiring 12-14 GB of VRAM. ```python quantization = "8-bit (Quanto)" # Uses: black-forest-labs/FLUX.2-dev + runtime quantization # Memory: ~12-14 GB VRAM # Speed: Medium # Quality: Excellent # Note: Fallback if BNB fails on MPS ``` -------------------------------- ### Database Migration Script (Python) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/FLUX2_MIGRATION_GUIDE.md A Python script for migrating database records to support FLUX.2. It includes features like automatic backups and a dry-run option for safe execution. ```python # Database migration script # Automatic backup # Dry-run support ``` -------------------------------- ### Configure No Quantization (Python) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/FLUX2_MIGRATION_GUIDE.md Sets quantization to 'None' for full precision (bfloat16), offering the best quality but requiring the most memory. This configuration uses the black-forest-labs/FLUX.2-dev model and requires 24+ GB of VRAM, providing the fastest speed if sufficient VRAM is available. ```python quantization = "None" # Uses: black-forest-labs/FLUX.2-dev (bfloat16) # Memory: ~24+ GB VRAM # Speed: Fastest (if enough VRAM) # Quality: Best ``` -------------------------------- ### Training Configuration Structure (JSON) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/API.md Defines the structure for a comprehensive training configuration, likely used for LoRA model training. It includes settings for the model, training parameters, optimizer, saving, instrumentation, LoRA layers, and example data. ```json { "model": "dev", "seed": 42, "quantize": null, "steps": 20, "guidance": 3.0, "width": 512, "height": 512, "training_loop": { "num_epochs": 100, "batch_size": 1 }, "optimizer": { "name": "AdamW", "learning_rate": 1e-4 }, "save": { "checkpoint_frequency": 10, "output_path": "./temp_train/current_train" }, "instrumentation": { "plot_frequency": 1, "generate_image_frequency": 20, "validation_prompt": "photo of sks dog" }, "lora_layers": { "single_transformer_blocks": { "block_range": { "start": 0, "end": 38 }, "layer_types": [ "proj_out", "proj_mlp", "attn.to_q", "attn.to_k", "attn.to_v" ], "lora_rank": 4 } }, "examples": { "path": "../../temp_images", "images": [ { "image": "filename.jpg", "prompt": "description" } ] } } ``` -------------------------------- ### Force Specific GPU Usage with CUDA Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/SETUP.md Use the `CUDA_VISIBLE_DEVICES` environment variable to specify which GPU should be used by the application. This is useful in multi-GPU systems to direct computation to a particular device. ```python # Force specific GPU import os os.environ["CUDA_VISIBLE_DEVICES"] = "0" ``` -------------------------------- ### Clear Hugging Face Cache to Force Model Update Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/SETUP.md Remove the local Hugging Face cache to force the re-download of models. This is useful when models have been updated on the Hugging Face Hub and you need to ensure you are using the latest versions. ```bash # Clear Hugging Face cache rm -rf ~/.cache/huggingface/ ``` -------------------------------- ### Configure Quantization Dropdown (Python) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/QUANTIZATION.md Configures a Gradio dropdown for selecting quantization options. It defaults to '8-bit' for optimal memory usage and provides information about the memory reduction benefits. ```python gr.Dropdown( label="Quantization - Memory optimisation", choices=["None", "8-bit"], value="8-bit", # Default to 8-bit for optimal memory usage info="8-bit: ~70% memory reduction, None: no optimization" ) ``` -------------------------------- ### Initialize and Manage Database with FluxForge Studio Source: https://context7.com/vincentgourbin/fluxforge-studio/llms.txt Handles database operations for storing and retrieving image generation history. Includes functions to initialize the SQLite database, save generation results (standard and FLUX.2), load the history, retrieve specific image details, and delete images. Requires functions from `core.database`. ```python from core.database import ( init_db, save_standard_generation, save_flux2_generation, load_history, get_image_details, delete_image ) # Initialize database (creates tables if needed) init_db() ``` -------------------------------- ### Queue Helper Functions Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/architecture.md This module provides helper functions for creating queue tasks across various generation types (standard, FLUX Fill, Kontext). It emphasizes parameter isolation using deep copies to prevent UI state interference and includes parameter validation and task description generation. ```python # Example usage (conceptual): from src.utils.queue_helpers import create_generation_task parameters = {"prompt": "A futuristic city", "steps": 50} task = create_generation_task("standard", parameters) # 'task' is now prepared for the queue system ``` -------------------------------- ### File Organization Structure Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/FEATURES.md Illustrates the directory structure for the mflux-gradio application, showing the placement of LoRA models, generated images, temporary files, and the history database. ```tree mflux-gradio/ ├── lora/ # LoRA model files ├── outputimage/ # Generated images ├── temp_images/ # Training image cache ├── temp_train/ # Training configurations ├── stepwise_output/ # Debug/intermediate outputs └── generated_images.db # History database ``` -------------------------------- ### Rollback Procedure: Restart Application (Shell) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/FLUX2_MIGRATION_GUIDE.md Shell command to restart the application after performing rollback steps, applying the restored code and downgraded dependencies. ```shell python main.py ``` -------------------------------- ### Rollback Procedure: Downgrade Gradio (Shell) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/FLUX2_MIGRATION_GUIDE.md Shell command to downgrade the Gradio library to a version compatible with the older system, ensuring proper functionality after a rollback. ```shell pip install "gradio>=4.0.0,<6.0.0" ``` -------------------------------- ### Activate Virtual Environment (Bash) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/FLUX2_CHANGELOG.md Commands to activate the Python virtual environment, either using venv or conda. This is a prerequisite for installing dependencies and running the application. ```bash source venv/bin/activate # or conda activate ``` -------------------------------- ### Legacy to FLUX.2 Mode Mapping (Python) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/FLUX2_MIGRATION_GUIDE.md A Python dictionary mapping legacy FLUX.1 generation modes to their corresponding FLUX.2 modes. This is used during the database migration process. ```python LEGACY_TO_FLUX2_MODE = { 'standard': 'text-to-image', 'flux_fill': 'inpainting' or 'outpainting', # Auto-detected from metadata 'kontext': 'image-to-image', 'flux_depth': 'depth-guided', 'flux_canny': 'canny-guided', 'flux_redux': 'image-to-image', 'qwen_generation': 'text-to-image', 'controlnet': 'canny-guided' } ``` -------------------------------- ### Quantization for Memory Optimization Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/architecture.md This module focuses on memory optimization through quantization, specifically cross-platform 8-bit quantization using `optimum.quanto`. It includes device-specific compatibility checks and pipeline component quantization with error handling, aiming for significant memory reduction. ```python # Example usage (conceptual): from src.utils.quantization import quantize_model # Assuming 'model' is a PyTorch model quantized_model = quantize_model(model, bits=8) # 'quantized_model' uses less memory ``` -------------------------------- ### FLUX.2 Generator Class (Python) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/FLUX2_MIGRATION_GUIDE.md A Python snippet representing the core generator class for FLUX.2. It handles multiple generation modes, LoRA support, and quantization integration. ```python # Unified generator class # 7 generation modes # LoRA support (up to 3 simultaneous) # Quantization integration ``` -------------------------------- ### Get Image Details Function (Python) Source: https://github.com/vincentgourbin/fluxforge-studio/blob/main/docs/API.md Retrieves detailed generation parameters for a specific image based on its index in the history. Returns a formatted string containing all parameters. ```python def get_image_details(index: int) -> str: ```