Skip to content

saurabh19304/AI_image_generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI_image_generator

AI Image Generator with Hugging Face API :- This project is an AI-powered image generation web application that allows users to input a text prompt and generate high-quality images using various Hugging Face diffusion models. The application includes a clean UI with light/dark themes, model selection, aspect ratio control, and advanced features such as custom error alerts, loading spinners, and result downloading.

✨ Built with: Vanilla JavaScript, HTML, CSS, Hugging Face Inference API

πŸš€ Features πŸ” Text-to-Image Generation using Hugging Face inference models

🎨 Multiple Model Support β€” choose from a list of diffusion models

πŸ”’ Image Count Selector β€” generate multiple images at once

πŸ“ Aspect Ratio Options β€” customize the width-to-height ratio

🎲 Prompt Suggestions β€” click-to-generate random prompts

πŸŒ— Dark/Light Theme Toggle β€” theme preference saved across sessions

⏳ Loading Spinners while images are being fetched

🧾 Styled Error Alerts for unavailable models (custom alerts)

πŸ“₯ One-click Image Download

πŸ“± Fully Responsive Design for desktop and mobile users

🧠 How It Works User enters a prompt (e.g., "A fantasy dragon flying over snowy mountains").

Chooses:

AI Model (e.g., stabilityai/stable-diffusion)

Number of images to generate

Aspect ratio (1:1, 4:3, 16:9, etc.)

On form submission:

A loading card is shown for each image

A POST request is sent to Hugging Face's inference API with the input prompt and model

The image blob is returned and displayed in the UI

The image is downloadable directly from the preview

If a model is unavailable:

A custom alert box is shown suggesting the user to try a different model

πŸ“‚ Folder Structure pgsql Copy Edit /project-root β”œβ”€β”€ index.html β”œβ”€β”€ style.css β”œβ”€β”€ script.js β”œβ”€β”€ alert.js (Custom styled alert box) └── README.md

πŸ” API Key Protection (Important) For development, your Hugging Face API key is required to be stored in script.js.

--> PLEASE REPLACE YOUR HUGGING FACE API KEY WITH THE PROMPT your_huggingface_API AT API_KEY. (As I can not share my API key publicly)

⚠️ Rate Limits & API Key Info The Hugging Face Inference API has rate limits:

Free accounts: 30 requests/month

To continue using the app after hitting limits:

Upgrade to a paid Hugging Face plan

Generate a new key from another Hugging Face account

Or host your own model using transformers locally

πŸ“Έ Preview Here’s how the app looks: https://saurabh19304.github.io/AI_image_generator/

Replace your Hugging Face API key in script.js:

js Copy Edit const API_KEY = 'your_huggingface_key_here';

🎯 Future Improvements Add drag-and-drop image preview area

Enable saving prompt history

Connect to a backend for safer API handling

Add login system to track usage

πŸ™‹β€β™‚οΈ About Me I created this project as a part of my learning journey, writing most of the code manually. It was a valuable experience combining real-time coding, UI design, and integrating external APIs. Some parts of the code involved trial and error and learning on the go β€” I plan to revisit and document those areas for better understanding.

πŸ“¬ Feedback If you have suggestions, improvements, or want to collaborate, feel free to open an issue.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors