This project implements an intelligent image editing and refinement system called EMage (Editing Mage/Image) that combines advanced Flux diffusion models with Vision-Language Model (VLM) evaluation to create a closed-loop improvement pipeline for generated images.
The EMage pipeline implements a sophisticated dual-stream optimization approach that alternates between prompt refinement and image manipulation based on semantic evaluation of generation quality. The system leverages three specialized Flux diffusion models and integrates them with Google's Gemini Pro Vision for automated assessment and refinement.
EMage employs a dynamic model selection approach with the following diffusion models:
Flux Base Model
black-forest-labs/FLUX.1-devFlux Canny Control Model
black-forest-labs/FLUX.1-Canny-devFlux Fill Model
black-forest-labs/FLUX.1-Fill-devAll Flux models are built on the same core architecture with specialized training for their respective tasks. Each model contains approximately 12 billion parameters and implements advanced attention mechanisms for high-quality image generation and manipulation.
The system integrates Google's Gemini API for multi-modal analysis:
The EMage feedback loop implements the following technical workflow:
pip install -r requirements.txt
pip install controlnet-aux
pip install git+https://github.com/huggingface/image_gen_aux
.env file with your API keysGEMINI_API_KEY=your_gemini_api_key_hereHF_TOKEN=your_huggingface_token_here (required for accessing Flux models)Our system implements an intelligent feedback loop that utilizes an algorithmic approach to model selection based on issue classification:
Initial Generation Phase:
VLM Evaluation Phase:
Strategy Determination Phase:
Model Selection Logic:
Execution Phase:
Iterative Refinement:
from flux_vlm_pipeline.pipeline import FluxVLMPipeline
# Initialize the EMage pipeline
emage = FluxVLMPipeline()
# Generate and refine an image with EMage
results = emage.generate_and_evaluate(
prompt="A photorealistic mountain landscape with pine trees and a lake reflecting the sunset",
num_iterations=3,
guidance_scale=7.5,
num_inference_steps=30,
seed=42, # For reproducibility
width=1024,
height=1024
)
# Access the final image and refined prompt
final_image = results["final_image"]
final_prompt = results["final_prompt"]
satisfaction_score = results["satisfaction_score"]
# Display the refinement history
history = results["history"]
The EMage system loads the black-forest-labs/FLUX.1-dev model through the diffusers FluxPipeline interface:
flux_pipeline = FluxPipeline.from_pretrained(
FLUX_BASE_MODEL_ID,
use_auth_token=HF_TOKEN
)
Key parameters for optimal generation:
The EMage system utilizes conditional image generation through the Flux Control Pipeline:
control_pipeline = FluxControlPipeline.from_pretrained(
FLUX_CANNY_MODEL_ID,
use_auth_token=HF_TOKEN
)
Key conditioning parameters:
For targeted refinements, EMage implements mask-based inpainting:
inpaint_pipeline = FluxFillPipeline.from_pretrained(
FLUX_FILL_MODEL_ID,
use_auth_token=HF_TOKEN
)
Inpainting parameters:
The EMage pipeline implements several memory optimization strategies:
enable_model_cpu_offload() to reduce VRAM footprintEMage builds on several key technical innovations:
This project is provided as an open-source implementation under MIT License.
6 commits
Python
100.0%
This project implements an intelligent image editing and refinement system called EMage (Editing Mage/Image) that combines advanced Flux diffusion models with Vision-Language Model (VLM) evaluation to create a closed-loop improvement pipeline for generated images.
The EMage pipeline implements a sophisticated dual-stream optimization approach that alternates between prompt refinement and image manipulation based on semantic evaluation of generation quality. The system leverages three specialized Flux diffusion models and integrates them with Google's Gemini Pro Vision for automated assessment and refinement.
EMage employs a dynamic model selection approach with the following diffusion models:
Flux Base Model
black-forest-labs/FLUX.1-devFlux Canny Control Model
black-forest-labs/FLUX.1-Canny-devFlux Fill Model
black-forest-labs/FLUX.1-Fill-devAll Flux models are built on the same core architecture with specialized training for their respective tasks. Each model contains approximately 12 billion parameters and implements advanced attention mechanisms for high-quality image generation and manipulation.
The system integrates Google's Gemini API for multi-modal analysis:
The EMage feedback loop implements the following technical workflow:
pip install -r requirements.txt
pip install controlnet-aux
pip install git+https://github.com/huggingface/image_gen_aux
.env file with your API keysGEMINI_API_KEY=your_gemini_api_key_hereHF_TOKEN=your_huggingface_token_here (required for accessing Flux models)Our system implements an intelligent feedback loop that utilizes an algorithmic approach to model selection based on issue classification:
Initial Generation Phase:
VLM Evaluation Phase:
Strategy Determination Phase:
Model Selection Logic:
Execution Phase:
Iterative Refinement:
from flux_vlm_pipeline.pipeline import FluxVLMPipeline
# Initialize the EMage pipeline
emage = FluxVLMPipeline()
# Generate and refine an image with EMage
results = emage.generate_and_evaluate(
prompt="A photorealistic mountain landscape with pine trees and a lake reflecting the sunset",
num_iterations=3,
guidance_scale=7.5,
num_inference_steps=30,
seed=42, # For reproducibility
width=1024,
height=1024
)
# Access the final image and refined prompt
final_image = results["final_image"]
final_prompt = results["final_prompt"]
satisfaction_score = results["satisfaction_score"]
# Display the refinement history
history = results["history"]
The EMage system loads the black-forest-labs/FLUX.1-dev model through the diffusers FluxPipeline interface:
flux_pipeline = FluxPipeline.from_pretrained(
FLUX_BASE_MODEL_ID,
use_auth_token=HF_TOKEN
)
Key parameters for optimal generation:
The EMage system utilizes conditional image generation through the Flux Control Pipeline:
control_pipeline = FluxControlPipeline.from_pretrained(
FLUX_CANNY_MODEL_ID,
use_auth_token=HF_TOKEN
)
Key conditioning parameters:
For targeted refinements, EMage implements mask-based inpainting:
inpaint_pipeline = FluxFillPipeline.from_pretrained(
FLUX_FILL_MODEL_ID,
use_auth_token=HF_TOKEN
)
Inpainting parameters:
The EMage pipeline implements several memory optimization strategies:
enable_model_cpu_offload() to reduce VRAM footprintEMage builds on several key technical innovations:
This project is provided as an open-source implementation under MIT License.
6 commits
Python
100.0%