A Gradio-based demonstration for the Qwen/Qwen-Image-Edit-2509 model with 3D lighting control using the Multi-Angle-Lighting LoRA adapter. Allows precise control of light source direction via interactive 3D viewport or sliders for azimuth and elevation. Supports fast inference (4 steps default) with Flash Attention 3, bfloat16, and dynamic prompt generation. Features auto-resizing (multiples of 8 up to 1024px), custom OrangeRed theme, and responsive layout.
Demo.mp4
- 3D Lighting Control: Interactive Three.js viewport with draggable handles for azimuth (horizontal) and elevation (vertical) angles; snaps to predefined positions (e.g., Front, Right, Above).
- Slider Controls: Manual adjustment for azimuth (0-315°) and elevation (-90-90°) with real-time prompt preview.
- Lazy LoRA Loading: Multi-Angle-Lighting adapter loads on first use to minimize VRAM.
- Rapid Inference: 4-step default with bfloat16 on CUDA; supports up to 20 steps.
- Auto-Resizing: Preserves aspect ratio, snaps to multiples of 8 (up to 2048px).
- Custom Theme: OrangeRedTheme with clean, responsive design.
- Prompt Generation: Dynamically builds lighting prompts (e.g., "Light source from the Front").
- Queueing: Up to default Gradio queue limits for concurrent jobs.
- Python 3.10 or higher.
- CUDA-compatible GPU (required for bfloat16 and Flash Attention 3).
- Stable internet for initial model/LoRA downloads.
- Clone the repository:
git clone https://github.com/PRITHIVSAKTHIUR/Qwen-Image-Edit-3D-Lighting-Control.git cd Qwen-Image-Edit-3D-Lighting-Control - Install dependencies:
First, install pre-requirements:
Then, install main requirements:
pip install -r pre-requirements.txtpre-requirements.txt content:pip install -r requirements.txtrequirements.txt content:pip>=23.0.0git+https://github.com/huggingface/accelerate.git git+https://github.com/huggingface/diffusers.git git+https://github.com/huggingface/peft.git transformers==4.57.3 huggingface_hub sentencepiece torchvision kernels spaces hf_xet gradio #gradio@6 torch==2.8.0 numpy av - Start the application:
The demo launches at
python app.pyhttp://localhost:7860.
- Upload Image: Add an image via the input component.
- Control Lighting: Use the 3D viewport (drag yellow/blue handles) or sliders for azimuth/elevation.
- Preview Prompt: View auto-generated lighting prompt; edit if needed.
- Configure (Optional): Adjust seed, guidance scale, steps, height/width in Advanced Settings.
- Generate: Click "Generate Image" to produce output.
| Adapter | Use Case |
|---|---|
| Multi-Angle-Lighting | Precise directional lighting control |
- Adapter Loading: First run downloads LoRA; monitor console.
- OOM: Reduce steps/resolution; clear cache with
torch.cuda.empty_cache(). - Flash Attention Fails: Fallback to default; requires compatible CUDA.
- No Output: Ensure image uploaded and prompt valid; check console.
- 3D Viewport Issues: Ensure browser supports WebGL/Three.js.
Contributions welcome! Add new adapters to ADAPTER_SPECS, enhance 3D controls, or improve prompts. Submit pull requests via the repository.
Repository: https://github.com/PRITHIVSAKTHIUR/Qwen-Image-Edit-3D-Lighting-Control.git
Apache License 2.0. See LICENSE for details. Built by Prithiv Sakthi. Report issues via the repository.