https://github.com/bchachar/image-generation
A Streamlit app for generating AI images using Stable Diffusion with prompt similarity scoring and image gallery.
https://github.com/bchachar/image-generation
artificial-intelligence clip image-generation sqlalchemy stable-diffusion streamlit
Last synced: 2 months ago
JSON representation
A Streamlit app for generating AI images using Stable Diffusion with prompt similarity scoring and image gallery.
- Host: GitHub
- URL: https://github.com/bchachar/image-generation
- Owner: bchachar
- Created: 2025-05-17T15:07:46.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-17T15:43:22.000Z (about 1 year ago)
- Last Synced: 2025-06-17T06:01:56.585Z (about 1 year ago)
- Topics: artificial-intelligence, clip, image-generation, sqlalchemy, stable-diffusion, streamlit
- Language: Python
- Homepage:
- Size: 19.3 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# π AI Image Generator with Stable Diffusion + CLIP Evaluation
This Streamlit web app allows you to generate images using various pre-trained **Stable Diffusion** models and evaluates the generated image against the input prompt using **CLIP similarity scoring**. The generated images, their prompts, model used, and similarity scores are saved in a SQLite database and displayed in a paginated gallery and sidebar history.
---

---
## πΈ Features
* π₯ Choose from multiple Stable Diffusion models (via Hugging Face)
* πΌοΈ Generate high-quality AI images from text prompts
* π Saves each image, prompt, and model info into a local SQLite database
* π§ Evaluates image-to-prompt similarity using OpenAI's CLIP model
* ποΈ Gallery view with pagination and prompt/model/similarity display
* π Sidebar shows recent image history
* π©οΈ Clear all history with a single click
---
## π Getting Started
### 1. Clone the Repository
```bash
git clone https://github.com/bchachar/image-generation.git
cd image-generation
```
### 2. Set Up a Virtual Environment (recommended)
```bash
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
```
### 3. Install Dependencies
```bash
pip install -r requirements.txt
```
> You need to have PyTorch installed with GPU support (`torch.cuda.is_available()`) for best performance.
### 4. Run the App
```bash
streamlit run app.py
```
---
## π Requirements
```txt
streamlit
transformers
torch
accelerate
scipy
safetensors
diffusers
Pillow
sqlalchemy
```
---
## π‘ How It Works
1. You enter a **prompt** and select a **Stable Diffusion model**.
2. The app generates an image using the selected model.
3. The image is evaluated with OpenAI's **CLIP** model to determine how well it matches the prompt.
4. The image, prompt, model name, and similarity score are saved in `history.db`.
5. The gallery displays the most recent images with prompt, model name, and similarity.
### π§ CLIP Similarity
We use OpenAIβs CLIP model (`ViT-B/32`) to compute the cosine similarity between the prompt and generated image. This gives a percentage score (0β100) indicating how well the image matches the text prompt.
---
## π Folder Structure
```
.
βββ app.py # Streamlit app
βββ requirements.txt # Python dependencies
βββ history.db # SQLite DB (auto-created)
βββ generated_images/ # Folder for saved images
βββ README.md # You're here!
```
---
## Clear History
Use the **"Clear History"** button in the sidebar to remove all stored images and data from the database.
---
## π License
This project is licensed under the MIT License. See `LICENSE` file for details.
---
## π Acknowledgements
* [Hugging Face Diffusers](https://github.com/huggingface/diffusers)
* [OpenAI CLIP](https://github.com/openai/CLIP)
* [Streamlit](https://streamlit.io/)