A modern image generation application built with Next.js, React, and Tailwind CSS. Generate images using Google Gemini, xAI Grok, Hugging Face FLUX.1-Kontext, or Qwen with a beautiful glass morphism UI.
- π¨ Modern glass morphism design
- π± Multiple layout options (Landscape, Mobile, Square)
- β‘ Fast image generation using Google Gemini, xAI Grok, Hugging Face FLUX.1-Kontext, or Qwen
- π€ Model switching between Google, Grok, FLUX.1-Kontext, and Qwen
- πΌοΈ Image preview and download
- β³ Beautiful loading screen
- βοΈ AI-powered text autocomplete and spell correction
- πΌοΈ Image-to-image generation with reference images (Google Gemini, FLUX.1-Kontext, and Qwen)
- Node.js 18+ and npm
- Clone the repository and install dependencies:
npm install-
Configure API keys (see Configuration section below)
-
Run the development server:
npm run dev- Open http://localhost:3000 in your browser.
Create a .env.local file in the root directory with the following variables:
GOOGLE_API_KEY=your_google_api_key_here
GOOGLE_MODEL=gemini-2.5-flash-image # Optional, defaults to gemini-2.5-flash-image for image generation- GOOGLE_API_KEY: Your Google API key (required) - Get it from Google AI Studio
- GOOGLE_MODEL: The model name (optional, defaults to
gemini-2.5-flash-imagefor image generation)
Image Generation: The app uses Gemini's native image generation capabilities. See the documentation for details.
GROK_API_KEY=your_grok_api_key_here
# OR alternatively:
XAI_API_KEY=your_grok_api_key_here
# Optional: Customize models
GROK_MODEL=grok-2-image-1212 # Image generation model (default: grok-2-image-1212)
GROK_COMPLETION_MODEL=grok-4-fast-non-reasoning # Text completion model (default: grok-4-fast-non-reasoning)- GROK_API_KEY or XAI_API_KEY: Your Grok API key (required) - Both are supported for compatibility
- GROK_MODEL: Image generation model (optional, defaults to
grok-2-image-1212) - GROK_COMPLETION_MODEL: Text completion model (optional, defaults to
grok-4-fast-non-reasoning)
Obtaining a Grok API Key:
- Sign up for an account at x.ai or visit the xAI Developer Console
- Navigate to API Keys section in your account settings
- Generate a new API key
API Documentation:
- Official xAI API documentation: https://docs.x.ai/
- Image generation endpoint: https://docs.x.ai/docs/api-reference#image-generations
- Chat completions endpoint: https://docs.x.ai/docs/api-reference#chat-completions
Note: Grok's image generation API supports fixed dimensions, but the app will pass your selected layout dimensions in case the API supports them in future updates. Reference images are not supported by Grok - use Google Gemini, FLUX.1-Kontext, or Qwen for image-to-image generation.
HF_TOKEN=your_huggingface_token_here
HF_MODEL=black-forest-labs/FLUX.1-Kontext-dev # Image generation model (default: FLUX.1-Kontext-dev)
HF_PROVIDER=fal-ai # Provider for fast inference (default: fal-ai)- HF_TOKEN: Your Hugging Face API token (required) - Get it from Hugging Face Settings
- HF_MODEL: The Hugging Face model to use (optional, defaults to
black-forest-labs/FLUX.1-Kontext-dev) - HF_PROVIDER: The inference provider (optional, defaults to
fal-aifor fast inference)
Obtaining a Hugging Face Token:
- Sign up at Hugging Face
- Go to Settings β Access Tokens
- Create a new token with read permissions
API Documentation: Hugging Face Inference API
Note: FLUX.1-Kontext supports both text-to-image and image-to-image generation with reference images using Hugging Face's inference API.
HF_TOKEN=your_huggingface_token_here
HF_MODEL2=Qwen/Qwen-Image-Edit # Qwen image-to-image model (default: Qwen/Qwen-Image-Edit)- HF_TOKEN: Your Hugging Face API token (required) - Same token as FLUX.1-Kontext
- HF_MODEL2: The Qwen model to use (optional, defaults to
Qwen/Qwen-Image-Edit)
Obtaining a Hugging Face Token:
- Sign up at Hugging Face
- Go to Settings β Access Tokens
- Create a new token with read permissions
API Documentation: Hugging Face Inference API
Important Notes:
- Qwen uses Hugging Face's image-to-image inference endpoint
- Reference images are REQUIRED for Qwen - Qwen is only available when a reference image is uploaded
- Qwen supports layout dimensions (1:1, 16:9, 9:16, etc.) for image-to-image generation
- The Qwen model button will be disabled until a reference image is uploaded
ImageGen/
βββ app/
β βββ api/
β β βββ complete/
β β β βββ route.ts # API route for text autocomplete/correction
β β βββ generate/
β β βββ route.ts # API route for image generation
β βββ globals.css # Global styles
β βββ layout.tsx # Root layout
β βββ page.tsx # Home page
βββ components/
β βββ AutocompleteTextarea.tsx # Textarea with AI autocomplete and correction
β βββ ImagePreview.tsx # Image preview component
β βββ ImageStudio.tsx # Main studio component
β βββ LayoutSelector.tsx # Layout selection UI
β βββ LoadingScreen.tsx # Loading state component
β βββ ModelSelector.tsx # Model selection UI (Google/Grok)
βββ lib/
βββ nanobanana.ts # Image generation client wrapper
- Text-to-Image: Generate images from text prompts (Google, Grok, FLUX.1-Kontext)
- Image-to-Image: Upload a reference image to guide the generation (Google Gemini, FLUX.1-Kontext, and Qwen)
β οΈ Reference images are not supported by Grok modelβ οΈ Reference images are required for Qwen model- For image-to-image generation, use Google Gemini, FLUX.1-Kontext, or Qwen
- Layout Options: Choose from Landscape (16:9), Mobile (9:16), or Square (1:1) aspect ratios
- Model Selection: Switch between Google Gemini, xAI Grok, Hugging Face FLUX.1-Kontext, and Qwen models
The app includes intelligent text completion powered by Grok:
- Autocomplete: As you type, the AI suggests completions (shown as ghost text)
- Spell Correction: Automatically corrects spelling and grammar errors
- Tab to Accept: Press Tab to accept the suggested completion or correction
Note: The autocomplete feature requires a Grok API key to be configured.
Build the application for production:
npm run build
npm startTo bypass geographic restrictions with Google's image generation API, deploy your app to Vercel:
-
Push your code to GitHub
git init git add . git commit -m "Initial commit" git remote add origin <your-github-repo-url> git push -u origin main
-
Deploy to Vercel:
- Go to vercel.com
- Import your GitHub repository
- Add your environment variables:
GOOGLE_API_KEY: Your Google API key (required for Google model)GOOGLE_MODEL:gemini-2.5-flash-image(optional)GROK_API_KEYorXAI_API_KEY: Your Grok API key (required for Grok model)GROK_MODEL:grok-2-image-1212(optional)GROK_COMPLETION_MODEL:grok-4-fast-non-reasoning(optional)HF_TOKEN: Your Hugging Face token (required for FLUX.1-Kontext and Qwen models)HF_MODEL:black-forest-labs/FLUX.1-Kontext-dev(optional, for FLUX.1-Kontext)HF_PROVIDER:auto(optional, for FLUX.1-Kontext)HF_MODEL2:Qwen/Qwen-Image-Edit(optional, for Qwen)
- Deploy
-
Why Vercel works: Vercel runs your server-side API routes on infrastructure in supported regions (US by default), which bypasses the geographic restriction.
You can also deploy to:
- AWS (us-east-1 or other supported regions)
- Google Cloud Platform (in a supported region)
- Azure (in a supported region)
Just make sure your server is located in a region where Google's image generation API is available. See Google's available regions for details.
The app includes comprehensive error handling:
- Network errors show connection issues
- API errors display the status code and error message
- Missing configuration prompts you to add the API key
- Check the browser console and server logs for detailed error information if generation fails
ISC