A SwiftUI-based iOS application that demonstrates image editing and modification using Google's Gemini Flash AI. This application provides a simple and intuitive interface for users to transform and edit their images using AI, guided by text prompts.
Note: For now, you can simply drop the GeminiAPIService file into your own Xcode projects to use it. I'll consider converting this to a Swift Package Manager package if more people want to use it that way.
This is test/demo code only. This implementation could stop working at any time if the Gemini API changes. This is not intended for production use and is provided as-is without any guarantees.
- 🎨 AI Image Editing: Transform and modify existing images using text instructions
- 🖼️ Image Input Required: Upload the image you want to edit
- 🔄 Image Transformation: Modify image style, content, and characteristics
- 📝 Text-Guided Editing: Use natural language to describe your desired image modifications
Gemini Flash is Google's AI model specifically designed for image editing and modification. Unlike traditional text-to-image generation, Gemini Flash specializes in transforming existing images based on text instructions while maintaining the core elements and structure of the original image.
- Clone the repository
- Open the project in Xcode
- Replace
YOUR_API_KEY_HERE
inContentView.swift
with your actual Gemini API key - Build and run the application
Note: This project has no external package dependencies - you only need a Gemini API key to get started.
- Select an iOS simulator from the device dropdown in Xcode (e.g., iPhone 15)
- Click the Run button (
▶️ ) or press Cmd+R - The app will build and launch in the simulator
- Use the photo picker to select an image from the simulator's photo library
- Test different prompts to see how Gemini Flash transforms images
To use the Gemini Flash API in your own Swift projects:
- Copy the
GeminiAPIService.swift
file into your Xcode project - Initialize the service with your API key:
let geminiService = GeminiAPIService(apiKey: "YOUR_API_KEY")
- Call the image editing method with a base64-encoded image and your prompt:
Task { let result = try await geminiService.editImage( imageBase64: encodedImageString, prompt: "Your editing instructions here" ) // Handle the result... }
- The API returns a base64-encoded string that you can convert back to an image:
if let data = Data(base64Encoded: result), let modifiedImage = UIImage(data: data) { // Use the modified image }
- Launch the application
- Upload the image you want to edit
- Enter your editing instructions in the text field (e.g., "Make this image more vibrant" or "Convert this to watercolor style")
- Tap the "Edit Image" button
- Wait for Gemini Flash to process and modify your image
- The edited image will appear below the input field
This project is licensed under the MIT License
- Built with Google's Gemini AI API