Skip to content

iritman/ai-image-editing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

🎨 OpenRouter Image Generator

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.

✨ Features

  • 📁 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

📋 Prerequisites

  • Python 3.7 or higher
  • OpenRouter API key
  • Internet connection for API requests

🚀 Installation

  1. Clone or download the project:

    git clone <repository-url>
    cd gemini-image-preview
  2. Create a virtual environment (recommended):

    python -m venv venv
  3. Activate the virtual environment:

    • On Windows:
      venv\Scripts\activate
    • On macOS/Linux:
      source venv/bin/activate
  4. Install required dependencies:

    pip install requests

⚙️ Configuration

  1. Get your OpenRouter API key:

    • Visit OpenRouter
    • Sign up for an account
    • Generate an API key
  2. Update the API key in the code:

    • Open app.py
    • Replace the API_KEY variable with your actual OpenRouter API key:
      API_KEY = "your-openrouter-api-key-here"

📂 Project Structure

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

🎯 Usage

  1. Prepare your input images:

    • Place the images you want to process in the images/ folder
    • Supported formats: PNG, JPG, JPEG, GIF, BMP, WebP
  2. Run the application:

    python app.py
  3. Follow the interactive prompts:

    • The application will display all found images
    • Enter your text prompt when requested
    • Wait for the processing to complete
  4. 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

💡 Example Usage

$ 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
==================================================

🔧 API Configuration

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

🚨 Error Handling

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

🔍 Troubleshooting

⚠️ Common Issues

  1. "No images found" error:

    • Ensure images are placed in the images/ folder
    • Check that image formats are supported
    • Verify folder permissions
  2. API authentication errors:

    • Verify your OpenRouter API key is correct
    • Check your account balance and usage limits
    • Ensure internet connectivity
  3. SSL/Connection errors:

    • Check your internet connection
    • Verify firewall settings
    • Try running from a different network
  4. Permission errors:

    • Ensure write permissions for the output folder
    • Run with appropriate user privileges

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

This project is open source and available under the MIT License.

💬 Support

For support and questions:

  • Check the troubleshooting section above
  • Review the OpenRouter API documentation
  • Create an issue in the project repository

🙏 Acknowledgments

  • 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

About

Demo project in Python for working with Google’s Nano Banana (Gemini 1.5 Flash Image) via OpenRouter API. Features: prompt-based image editing, background change, multi-image fusion, and saving AI-generated outputs. Perfect for AI developers and enthusiasts.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages