Quick Start
Hook API
useTextToImage(props)
Manages a text-to-image diffusion model pipeline.
Parameters
Diffusion model configuration
Callback triggered after each diffusion step for progress tracking
Prevent automatic model loading
Returns
Error object if loading or generation fails
Whether all pipeline components are loaded and ready
Whether image generation is in progress
Combined download progress for all models (0-1)
Generate an image from a text prompt.Parameters:
input: Text description of the desired imageimageSize: Target image dimension (e.g., 512 for 512x512)numSteps: Number of denoising steps (more = higher quality, slower)seed: Random seed for reproducibility
Interrupt the current generation process at the next step
Available Models
BK_SDM_TINY_VPRED_512
Tiny Stable Diffusion model optimized for 512x512 generation.- Output Size: 512x512 pixels
- Default Steps: 20
- Inference Time: ~30-60 seconds (device-dependent)
- Quality: Good for mobile, lower than full SD models
- Memory: ~1.5GB
BK_SDM_TINY_VPRED_256
Tiny Stable Diffusion model optimized for 256x256 generation.- Output Size: 256x256 pixels
- Default Steps: 20
- Inference Time: ~15-30 seconds
- Quality: Faster but lower resolution
- Memory: ~1GB
Complete Example
Use Cases
AI Art Generator
Create artistic images from descriptions:Product Visualization
Visualize products before creation:Concept Sketching
Generate concept sketches:Story Illustration
Generate illustrations for stories:Prompt Engineering
Effective Prompts
Craft prompts for better results:Negative Prompts
While the current API doesn’t support negative prompts directly, you can:Generation Parameters
Image Size
Choose appropriate size for your use case:Denoising Steps
Balance quality vs. speed:- 10 steps: Fast preview (~10-15 seconds)
- 20 steps: Good balance (~30 seconds)
- 30 steps: Better quality (~45 seconds)
- 50 steps: Best quality (~75 seconds)
Reproducibility
Use seeds for consistent results:Progress Tracking
Monitor generation progress:Interrupting Generation
Stop generation gracefully:Saving Generated Images
Performance Tips
Memory Management
- Text-to-image models are memory-intensive (~1-2GB)
- Close other apps during generation
- Test on target devices to ensure sufficient memory
Generation Speed
- Use 256x256 model for faster results
- Reduce denoising steps for previews
- Consider showing progress to keep users engaged
Battery Optimization
Type Reference
Limitations
- Model Quality: Mobile models are smaller than cloud-based alternatives
- Generation Time: 30-60 seconds per image on modern devices
- Memory Requirements: Requires 1-2GB RAM minimum
- Resolution: Currently limited to 512x512 or 256x256
- Prompt Understanding: May not understand complex or abstract prompts as well as larger models
Related
- Style Transfer - Apply artistic styles
- Image Embeddings - Visual feature extraction
- Custom Models - Use custom diffusion models