A beautiful AI-powered image generator built with HTML, CSS, and JavaScript. This application uses Hugging Face's powerful AI models to create stunning images from text descriptions.
- π¨ Generate stunning images from text prompts
- π€ Multiple AI models to choose from (FLUX, Stable Diffusion)
- β‘ Fast and responsive interface
- π₯ Download generated images
- π Secure API key management with serverless functions
- π« Beautiful UI with smooth animations
β¨ Try it now: https://ai-image-generator-nexaurro.vercel.app
- Frontend: HTML5, CSS3, Vanilla JavaScript
- Backend: Vercel Serverless Functions (Node.js)
- AI API: Hugging Face Inference API
- Hosting: Vercel
Before you begin, ensure you have:
- A GitHub account
- A Vercel account (free tier works great)
- A Hugging Face account and API token
- Go to Hugging Face and create an account (if you don't have one)
- Navigate to Settings β Access Tokens
- Click New Token
- Give it a name (e.g., "AI Image Generator")
- Select Read permission
- Copy the token (you'll need it for deployment)
-
Initialize Git repository (if not already done):
git init git add . git commit -m "Initial commit: AI Image Generator"
-
Create a new repository on GitHub:
- Go to GitHub
- Create a new repository (e.g., "ai-image-generator")
- Don't initialize with README (we already have files)
-
Push your code:
git remote add origin https://github.com/YOUR_USERNAME/ai-image-generator.git git branch -M main git push -u origin main
-
Go to Vercel and sign in
- You can sign in with your GitHub account
-
Import your GitHub repository:
- Click "Add New..." β "Project"
- Select "Import Git Repository"
- Find and select your
ai-image-generatorrepository - Click "Import"
-
Configure Environment Variables:
- Before clicking "Deploy", scroll down to Environment Variables
- Add the following variable:
- Name:
HUGGINGFACE_API_TOKEN - Value: [Your Hugging Face API token]
- Name:
- Click "Add"
-
Deploy:
- Click "Deploy"
- Wait for the deployment to complete (usually 1-2 minutes)
- Your site will be live at:
https://your-project-name.vercel.app
- Visit your deployed URL
- Enter a prompt (e.g., "A magical forest with glowing mushrooms")
- Click "Generate Image"
- Wait 30-60 seconds for the AI to create your image
- Download and enjoy!
To run this project locally with the serverless function:
-
Clone the repository:
git clone https://github.com/YOUR_USERNAME/ai-image-generator.git cd ai-image-generator -
Install Vercel CLI:
npm install -g vercel
-
Create a
.envfile in the root directory:HUGGINGFACE_API_TOKEN=your_token_here
-
Run the development server:
vercel dev
-
Open your browser to
http://localhost:3000
ai-image-generator/
βββ api/
β βββ generate.js # Serverless function (API proxy)
βββ index.html # Main HTML file
βββ styles.css # Styling
βββ vercel.json # Vercel configuration
βββ .gitignore # Git ignore file
βββ README.md # This file
- Your frontend (index.html) sends a request to
/api/generate - Vercel serverless function receives the request
- The function uses the API token from environment variables (secure)
- It calls the Hugging Face API on your behalf
- The image is returned to the frontend
- Your API key is never exposed in the browser or GitHub
Edit the <select id="model"> options in index.html:
<option value="your-model-name">Your Model Name</option>Edit styles.css to customize colors, fonts, and layout.
You can extend the api/generate.js file to add:
- Image size options
- Negative prompts
- Style presets
- Rate limiting
- Image history
- Make sure you added the
HUGGINGFACE_API_TOKENenvironment variable in Vercel - Redeploy your project after adding the variable
- This is normal for free-tier Hugging Face models
- Wait and try again after 30 seconds
- Check the browser console for errors
- Verify your API token is valid
- Try a different AI model
- FLUX.1-schnell: Fast generation, good quality
- FLUX.1-dev: Slower but higher quality
- Stable Diffusion XL: High-resolution images
- Stable Diffusion 1.5: Classic model, reliable
- "A futuristic city at night with neon lights and flying cars"
- "A magical forest with glowing mushrooms and fairy lights"
- "A steampunk robot playing chess in a Victorian library"
- "An underwater palace made of coral and pearls"
- "A cyberpunk samurai in a neon-lit Tokyo street"
Contributions are welcome! Feel free to:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
This project is open source and available under the MIT License.
AHANAF ABID SAZID
- Hugging Face for the amazing AI models
- Vercel for free hosting and serverless functions
- The open-source community for inspiration
Made by AHANAF ABID SAZID
If you found this project helpful, please give it a β on GitHub!