A powerful Python application that leverages the OpenRouter API to generate new images based on existing images and text prompts. This tool uses Google's Gemini 2.5 Flash Image Preview model to create stunning AI-generated images.
- 📁 Batch Image Processing: Process multiple images simultaneously from a designated input folder
- 🤖 AI-Powered Generation: Utilizes Google's advanced Gemini 2.5 Flash Image Preview model via OpenRouter API
- 🖼️ Multiple Format Support: Supports PNG, JPG, JPEG, GIF, BMP, and WebP image formats
- ⏰ Automatic Output Management: Generates timestamped output files to prevent overwrites
- 🛡️ Error Handling: Robust error handling with detailed feedback for troubleshooting
- 💬 Interactive Interface: User-friendly command-line interface with progress tracking
- Python 3.7 or higher
- OpenRouter API key
- Internet connection for API requests
-
Clone or download the project:
git clone <repository-url> cd gemini-image-preview
-
Create a virtual environment (recommended):
python -m venv venv
-
Activate the virtual environment:
- On Windows:
venv\Scripts\activate
- On macOS/Linux:
source venv/bin/activate
- On Windows:
-
Install required dependencies:
pip install requests
-
Get your OpenRouter API key:
- Visit OpenRouter
- Sign up for an account
- Generate an API key
-
Update the API key in the code:
- Open
app.py - Replace the
API_KEYvariable with your actual OpenRouter API key:API_KEY = "your-openrouter-api-key-here"
- Open
gemini-image-preview/
├── app.py # Main application file
├── images/ # Input images folder
│ ├── photo-A.png
│ └── photo-B.png
├── output/ # Generated images output folder
├── venv/ # Virtual environment (if created)
└── README.md # This file
-
Prepare your input images:
- Place the images you want to process in the
images/folder - Supported formats: PNG, JPG, JPEG, GIF, BMP, WebP
- Place the images you want to process in the
-
Run the application:
python app.py
-
Follow the interactive prompts:
- The application will display all found images
- Enter your text prompt when requested
- Wait for the processing to complete
-
Check the results:
- Generated images will be saved in the
output/folder - Files are named with timestamps to prevent overwrites
- Format:
{original_name}_openrouter_{timestamp}.png
- Generated images will be saved in the
$ python app.py
==================================================
OpenRouter Image Generator
==================================================
Found 2 image(s) in g:\Python-Projects\gemini-image-preview\images:
1. photo-A.png
2. photo-B.png
==================================================
Enter your prompt for image generation: Make this image look like a watercolor painting
Processing 2 image(s) with prompt: 'Make this image look like a watercolor painting'
==================================================
Processing image 1/2: photo-A.png
File saved to: g:\Python-Projects\gemini-image-preview\output\photo-A_openrouter_20240127_143052.png
✓ Successfully generated: photo-A_openrouter_20240127_143052.png
Processing image 2/2: photo-B.png
File saved to: g:\Python-Projects\gemini-image-preview\output\photo-B_openrouter_20240127_143058.png
✓ Successfully generated: photo-B_openrouter_20240127_143058.png
==================================================
Processing completed!
Check the output folder: g:\Python-Projects\gemini-image-preview\output
==================================================The application is configured to use:
- API Endpoint:
https://openrouter.ai/api/v1/chat/completions - Model:
google/gemini-2.5-flash-image-preview:free - Modalities: Image and Text generation
The application includes comprehensive error handling for:
- Missing or invalid API keys
- Network connectivity issues
- Invalid image formats
- API rate limits and errors
- File system permissions
-
"No images found" error:
- Ensure images are placed in the
images/folder - Check that image formats are supported
- Verify folder permissions
- Ensure images are placed in the
-
API authentication errors:
- Verify your OpenRouter API key is correct
- Check your account balance and usage limits
- Ensure internet connectivity
-
SSL/Connection errors:
- Check your internet connection
- Verify firewall settings
- Try running from a different network
-
Permission errors:
- Ensure write permissions for the output folder
- Run with appropriate user privileges
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.
For support and questions:
- Check the troubleshooting section above
- Review the OpenRouter API documentation
- Create an issue in the project repository
- OpenRouter for providing access to advanced AI models
- Google for the Gemini 2.5 Flash Image Preview model
- The Python community for excellent libraries and tools