An intelligent assistant for FLUX.1 Kontext models in Stable Diffusion WebUI Forge. Analyzes context images and generates optimized prompts using dual AI models.
FLUX.1 Kontext Image Limitations:
- 1 image: β Works perfectly - recommended for best results
- 2 images:
β οΈ May experience issues - use with caution- 3 images: π¨ DANGER ZONE - use at your own risk!
Memory Usage: Each additional image significantly increases VRAM consumption. Monitor your GPU memory when using multiple images.
- Overview
- Key Features
- System Requirements
- Installation
- Quick Start
- Features
- Documentation
- Troubleshooting
- Development
- Credits
- License
Kontext Assistant is an extension for Stable Diffusion WebUI Forge that automates prompt creation for FLUX.1 Kontext models. The extension uses advanced computer vision models to analyze images and generate detailed descriptions, which are then transformed into optimized prompts.
FLUX.1 Kontext is a specialized version of the FLUX.1 model capable of working with context images. Unlike standard models, it can use up to 3 reference images for better understanding of the desired output.
- Automation: Eliminates the need to manually describe images
- Accuracy: Uses AI for detailed analysis of composition, objects, and style
- Optimization: Generates prompts considering FLUX.1 Kontext limitations (512 tokens)
- Flexibility: Provides numerous settings and operation modes
- Florence-2 Base: Fast analysis and object detection
- PromptGen v2.0: Detailed descriptions and tag generation
- Automatic model switching based on task requirements
- Fast: Basic description in 2-3 seconds
- Standard: Balanced analysis
- Detailed: Complete analysis of all aspects
- Tags Only: Booru-style tag generation
- Composition: Focus on element arrangement
- Hundreds of styles across 14 comprehensive categories
- Material & Environment transforms for creative effects
- 10 scenarios including dual-image workflows
- Multiple arrangement options for dual-image mode
- User prompt management system
- RTX 4090/5090 support with automatic FP16
- Automatic model unloading from memory
- Multi-threaded processing with conflict protection
- Analysis result caching
- Save favorite prompts
- Quick access via dropdown
- Import/export styles
- OS: Windows 10/11, Linux, macOS
- Python: 3.10 or higher
- VRAM: 4GB
- RAM: 8GB
- Disk Space: 2GB for models
- VRAM: 6GB or more
- RAM: 16GB
- GPU: NVIDIA RTX 3060 or higher
- Disk Space: 5GB (including cache)
- Open Stable Diffusion WebUI Forge in your browser
- Go to Extensions tab
- Click Install from URL sub-tab
- Paste this URL:
https://github.com/yourusername/forge-kontext-assistant
- Click Install
- Go to Installed tab
- Click Apply and restart UI
- Clone the repository to extensions folder:
cd stable-diffusion-webui-forge/extensions
git clone https://github.com/E2GO/forge-kontext-assistant
- Restart WebUI - dependencies will install automatically
- Download the release archive
- Extract to
stable-diffusion-webui-forge/extensions/
- Install dependencies:
cd forge-kontext-assistant
pip install -r requirements.txt
- Load your image in Forge FluxKontext Pro
- Open "π¨ Prompt Builder" section
- Select "Style Transfer" from Scenario dropdown
- Choose styles from extensive categories or type custom style
- Click "Build Prompt" to generate optimized prompt
- Click "Generate" button to create your styled image
Not sure what you're seeing in the image? Don't know what something is called or what color it is? Want to recreate an image and need a prompt for it?
Use the Analyze feature:
- Click "Analyze All Images" button
- Choose analysis mode (Fast for quick overview, Detailed for full description)
- Use the analysis results to understand your image better
- Analysis Mode: Choose analysis mode
- Analyze All Images: Analyze all loaded images
- Analysis Results: Results with detailed description
- Scenario Selection: 10 scenarios for different tasks
- Style Library: 14 categories with hundreds of styles
- Dual-Image Mode: Combine two images with arrangement options
- Material/Environment Transforms: Creative transformation effects
- Token Counter: Real-time token tracking
- Direct Generation: Generate from within Prompt Builder
- Prompt Templates: Prompt templates
- Custom Styles: User styles management
- Auto-unload: Model auto-unload settings
- Performance Info: Performance information
- Style Transfer: Apply artistic styles to images
- Add/Remove Object: Add new elements or remove unwanted ones
- Replace Object: Transform one object into another
- Change Pose: Modify character poses
- Change Emotion: Alter facial expressions
- Change Lighting: Adjust lighting and mood
- Enhance/Restore Image: Improve quality and details
- Extend Canvas: Expand image boundaries (Outpainting)
- Dual-Image Mode: Combine two images creatively
- User Prompts: Use saved custom prompts
- Maximum: 512 tokens (not characters!)
- Warning: At 450+ tokens
- Counter: Real-time display
- Validation: Automatic check before generation
- Detailed Documentation - Technical information
- Credits and Sources - Resources used
- Check that images are loaded in KontextPro
- Click refresh button (π)
- Ensure image format is supported (PNG, JPG, WebP)
- Models download on first use (~1GB)
- Process may take 1-5 minutes depending on internet speed
- Check free disk space
The extension includes a universal cache clearing script that works on all platforms (Windows, Linux, macOS).
When to use it:
- Getting
h11
orhttpcore
errors - WebUI crashes or behaves strangely after updates
- Extension stops working after system changes
- UI elements not updating properly
How to use:
- Navigate to the extension folder
- Run the cache cleaner:
python clear_cache.py
What it does:
- Clears Python
__pycache__
directories (compiled bytecode) - Clears pip cache (downloaded packages)
- Clears Gradio temporary files (UI components)
- Optionally clears Kontext Assistant model cache
- Reinstalls the h11 module (common source of errors)
- Provides browser cache clearing instructions
Note: This is a safe operation that only removes temporary files. Your settings and custom styles are preserved.
- Enable Auto-unload in Advanced Settings
- Use Fast mode for quick tasks
- Check VRAM usage in Performance Info panel
- Ensure latest NVIDIA drivers are installed
- Check PyTorch version compatibility with your GPU
- Try reducing batch size in WebUI settings
This extension was fully developed using Claude AI by Anthropic. Claude helped with:
- System architecture and design
- Writing all code
- AI model integration
- Performance optimization
- Documentation creation
This project is based on and inspired by:
- forge2_flux_kontext by DenOfEquity - Base script code and resolution transfer from script to main interface
- 4o-ghibli-at-home by TheAhmadOsman - Many styles were used or inspired by this project
forge-kontext-assistant/
βββ scripts/
β βββ kontext.py # Main UI and logic
βββ ka_modules/
β βββ smart_analyzer.py # Dual-model system
β βββ image_analyzer.py # Florence-2 handling
β βββ prompt_builder.py # Prompt generation
β βββ token_utils.py # Token counting
β βββ styles/ # Style library modules
β β βββ anime_manga_styles.py
β β βββ art_movements_styles.py
β β βββ cartoon_styles.py
β β βββ cultural_styles.py
β β βββ digital_art_styles.py
β β βββ environment_transform_styles.py
β β βββ famous_artists_styles.py
β β βββ material_transform_styles.py
β β βββ photography_styles.py
β β βββ traditional_art_styles.py
β βββ ... # Other modules
βββ configs/
β βββ settings.json # Main settings
β βββ style_modifiers.json # Style modifiers
β βββ ... # Other configs
βββ javascript/
βββ kontext_set_dimensions.js # UI scripts
Pull requests are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature
) - Commit changes (
git commit -m 'Add some AmazingFeature'
) - Push to branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
- DenOfEquity - For the base forge2_flux_kontext code
- TheAhmadOsman - For style inspiration from 4o-ghibli-at-home
- Anthropic Claude AI - For development assistance
- Microsoft - For Florence-2 model
- Mitsua Diffusion - For PromptGen v2.0 model
- AUTOMATIC1111 & lllyasviel - For Stable Diffusion WebUI Forge
- Community - For testing and feedback
Distributed under the GNU Affero General Public License v3.0. See LICENSE for details.
Version: 1.0.1 | Status: Production Ready | Created with: Claude AI