A modern web application that generates images from text descriptions using Stable Diffusion AI model. Built with Streamlit and designed with a sleek dark theme interface.
- Text-to-Image Generation: Convert text prompts into high-quality images using Stable Diffusion
- Modern UI: Dark theme with gradient styling and responsive design
- Real-time Processing: Instant image generation with loading indicators
- Public Access: Automatically exposed via ngrok for easy sharing
- GPU Support: Optimized for CUDA when available, falls back to CPU
- Python 3.7+
- GPU with CUDA support (recommended) or CPU
- Internet connection for model downloads
- Upload all files to Google Colab
- Run the Colab-specific runner:
!python run_colab.py
- Clone or download all files to your local machine
- Install dependencies:
pip install -r requirements.txt
- Run the application:
python main.py
Use the local runner that automatically checks and installs dependencies:
python local_run.py
- Copy
.env.example
to.env
:
cp .env.example .env
- Add your ngrok auth token (optional):
NGROK_AUTH_TOKEN=your_ngrok_auth_token_here
Note: Ngrok auth token is optional for basic usage but recommended for persistent URLs.
-
Start the Application:
- Local:
python main.py
- Colab:
python run_colab.py
- Local:
-
Access the Interface: Click the ngrok URL that appears in the console
-
Generate Images:
- Enter a descriptive text prompt
- Click "Generate β€"
- Wait for the AI to process your request
- View your generated image
"A futuristic city skyline at night, cyberpunk style, neon lights"
"A serene mountain landscape with crystal clear lake, morning mist"
"Portrait of a wise old wizard, fantasy art style, detailed"
"Abstract art with vibrant colors and geometric patterns"
"A cute robot playing with butterflies in a magical garden"
- Responsive Design: Works on desktop and mobile devices
- Dark Theme: Easy on the eyes with blue gradient accents
- Input Validation: Prevents empty prompt submissions
- Loading States: Visual feedback during image generation
- Error Handling: User-friendly error messages
- Image Display: Rounded corners with glowing effects
- Base Model: CompVis/stable-diffusion-v1-4
- Framework: Hugging Face Diffusers
- Precision: Float32 (configurable)
- Model Caching: Uses Streamlit's
@st.cache_resource
for efficient loading - GPU Acceleration: Automatically detects and uses CUDA when available
- Background Processing: Runs Streamlit in a separate thread
text-to-image-generator/
βββ main.py # Main application entry point
βββ app.py # Auto-generated Streamlit app
βββ requirements.txt # Python dependencies
βββ setup.py # Package setup configuration
βββ .env.example # Environment variables template
βββ .env # Your environment variables (create from example)
βββ local_run.py # Local development runner
βββ run_colab.py # Google Colab runner
βββ README.md # This file
streamlit>=1.28.0
- Web application frameworkdiffusers>=0.21.0
- Stable Diffusion model implementationtransformers>=4.34.0
- Hugging Face transformers librarytorch>=2.0.0
- PyTorch deep learning frameworkaccelerate>=0.21.0
- Hugging Face acceleration librarysafetensors>=0.3.0
- Safe tensor serializationpyngrok>=6.0.0
- Python wrapper for ngrok tunnelingpython-dotenv>=1.0.0
- Environment variable management
- The first execution will download the Stable Diffusion model (~4GB)
- This may take several minutes depending on your internet connection
- Subsequent runs will be faster due to model caching
- GPU: NVIDIA GPU with 4GB+ VRAM (recommended)
- CPU: Multi-core processor (fallback option)
- RAM: 8GB+ system memory
- Storage: 10GB+ free space for model files
- Image generation can take 30-60 seconds per image
- CPU generation is significantly slower than GPU
- Some prompts may not produce expected results
"CUDA out of memory"
# Solution: The app will automatically fall back to CPU
# Or close other GPU-intensive applications
"Model download failed"
# Check internet connection
# Verify sufficient disk space (10GB+)
# Try running again (downloads can resume)
"Ngrok tunnel failed"
# Check if port 8501 is available
# Verify ngrok installation: pip install pyngrok
# Try restarting the application
"ModuleNotFoundError"
# Install missing dependencies
pip install -r requirements.txt
# Or use the local runner
python local_run.py
"Streamlit not found"
# Install Streamlit
pip install streamlit
# Or reinstall all dependencies
pip install -r requirements.txt
- Check the console output for detailed error messages
- Ensure all dependencies are properly installed
- Verify your Python version compatibility (3.7+)
- Make sure you have sufficient disk space for model downloads
# Install in development mode
pip install -e .
# Run with auto-reload
streamlit run app.py --server.runOnSave=true
# Build the package
python setup.py sdist bdist_wheel
# Install locally
pip install dist/text-to-image-generator-1.0.0.tar.gz
- The application uses ngrok to create public tunnels
- Be cautious when sharing ngrok URLs publicly
- Consider using ngrok auth tokens for better security
- The app runs on your local machine and processes are isolated
This project uses the Stable Diffusion model which has specific licensing terms. Please review the model's license before commercial use.
Feel free to submit issues, feature requests, or pull requests to improve this application.
- Fork the repository
- Create a virtual environment:
python -m venv venv
- Activate:
source venv/bin/activate
(Linux/Mac) orvenv\Scripts\activate
(Windows) - Install dependencies:
pip install -r requirements.txt
- Make your changes
- Test thoroughly
- Submit a pull request
- Multiple model support (SD 2.0, DALL-E, etc.)
- Batch image generation
- Image editing capabilities
- Custom model fine-tuning
- Advanced prompt engineering tools
- Image upscaling options
- Style transfer features
- API endpoint creation
- Docker containerization
- Database integration for image storage
Hardware | Generation Time | Memory Usage |
---|---|---|
RTX 3090 | 15-30 seconds | 8GB VRAM |
RTX 3060 | 30-45 seconds | 6GB VRAM |
CPU (16 cores) | 2-5 minutes | 8GB RAM |
- Hugging Face for the Diffusers library
- Stability AI for the Stable Diffusion model
- Streamlit for the web framework
- ngrok for public URL tunneling
If you encounter any issues or have questions:
- Check the troubleshooting section above
- Look for similar issues in the project issues
- Create a new issue with detailed information
- Include your system specs and error messages
**Happy generating! **
Made with β€οΈ by Zubair Hussain