Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ArtifyAI: Text-to-Image Generation
|
2 |
+
|
3 |
+
ArtifyAI is an innovative project that combines the power of Natural Language Processing (NLP) with image generation. This repository implements a pipeline using the T5 Transformer model for text summarization or generation and the Stable Diffusion model for creating images based on the generated text.
|
4 |
+
|
5 |
+
## Overview
|
6 |
+
|
7 |
+
ArtifyAI takes a text input, processes it through a T5 model, and then uses the processed output to generate an image using Stable Diffusion. This allows for seamless conversion of text descriptions into AI-generated images.
|
8 |
+
|
9 |
+
## Features
|
10 |
+
|
11 |
+
- **Text Processing**: Uses T5 (Text-to-Text Transfer Transformer) for summarizing or generating text from user inputs.
|
12 |
+
- **Image Generation**: Uses Stable Diffusion to create high-quality images from the text processed by the T5 model.
|
13 |
+
- **Combined Pipeline**: A simple Python function combines these models to produce stunning images from text.
|
14 |
+
|
15 |
+
## Installation
|
16 |
+
|
17 |
+
### Prerequisites
|
18 |
+
|
19 |
+
To run this project locally, ensure you have the following:
|
20 |
+
|
21 |
+
1. Python 3.7+
|
22 |
+
2. CUDA-compatible GPU (for faster performance with Stable Diffusion)
|
23 |
+
3. [Hugging Face Transformers](https://huggingface.co/transformers/) library
|
24 |
+
4. [Diffusers](https://huggingface.co/docs/diffusers/index) for Stable Diffusion
|
25 |
+
5. [PyTorch](https://pytorch.org/) with CUDA support (optional for faster image generation)
|
26 |
+
|
27 |
+
### Step-by-Step Setup
|
28 |
+
|
29 |
+
1. **Clone the Repository**:
|
30 |
+
```bash
|
31 |
+
git clone https://github.com/your-username/ArtifyAI.git
|
32 |
+
cd ArtifyAI
|
33 |
+
```
|
34 |
+
|
35 |
+
2. **Install Dependencies**:
|
36 |
+
It's best to use a virtual environment to manage dependencies.
|
37 |
+
```bash
|
38 |
+
pip install torch transformers diffusers
|
39 |
+
```
|
40 |
+
|
41 |
+
3. **Download the Pretrained Models**:
|
42 |
+
You'll need to load the models locally from Hugging Face. You can either download them using the code inside the notebook or by modifying it as follows:
|
43 |
+
```python
|
44 |
+
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
45 |
+
from diffusers import StableDiffusionPipeline
|
46 |
+
import torch
|
47 |
+
|
48 |
+
# Load models
|
49 |
+
t5_tokenizer = T5Tokenizer.from_pretrained("t5-small")
|
50 |
+
t5_model = T5ForConditionalGeneration.from_pretrained("t5-small")
|
51 |
+
ArtifyAI_model = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16)
|
52 |
+
|
53 |
+
# Set model to GPU (if available)
|
54 |
+
ArtifyAI_model = ArtifyAI_model.to("cuda" if torch.cuda.is_available() else "cpu")
|
55 |
+
```
|
56 |
+
|
57 |
+
4. **Run the Pipeline**:
|
58 |
+
A sample pipeline is included in `pipeline.py`. You can run it using:
|
59 |
+
```bash
|
60 |
+
python pipeline.py
|
61 |
+
```
|
62 |
+
|
63 |
+
5. **Text to Image Generation**:
|
64 |
+
You can generate images from text input using the following function:
|
65 |
+
```python
|
66 |
+
def t5_to_image_pipeline(input_text):
|
67 |
+
# T5 model processing
|
68 |
+
t5_inputs = t5_tokenizer.encode(input_text, return_tensors='pt', truncation=True)
|
69 |
+
summary_ids = t5_model.generate(t5_inputs, max_length=50, num_beams=5, early_stopping=True)
|
70 |
+
generated_text = t5_tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
71 |
+
|
72 |
+
# Generate image from text using Stable Diffusion
|
73 |
+
image = ArtifyAI_model(generated_text).images[0]
|
74 |
+
return image
|
75 |
+
```
|
76 |
+
|
77 |
+
## Usage
|
78 |
+
|
79 |
+
1. **Run the Jupyter Notebook**: You can open `ArtifyAI_v1_1.ipynb` in Jupyter to run the code interactively.
|
80 |
+
2. **Save and Load Models**: You can modify the notebook to save your models to Google Drive or a local directory.
|
81 |
+
3. **Custom Inputs**: Modify the text input in the pipeline to generate customized images based on different descriptions.
|
82 |
+
|
83 |
+
## Example
|
84 |
+
|
85 |
+
Here's an example of generating an image from text:
|
86 |
+
```python
|
87 |
+
image = t5_to_image_pipeline("A futuristic city skyline at sunset")
|
88 |
+
image.show()
|
89 |
+
|
90 |
+
## For Non-Technical Users
|
91 |
+
|
92 |
+
Even if you are new to AI, you can use ArtifyAI by following these simple steps:
|
93 |
+
|
94 |
+
1. **Install Python**: Download and install Python 3.7+ from the [official Python website](https://www.python.org/downloads/).
|
95 |
+
|
96 |
+
2. **Install Dependencies**: Follow the steps in the Installation section to install necessary packages using the `pip` command.
|
97 |
+
|
98 |
+
3. **Run the Code**: You can run the project directly by using the provided code snippets. If you face any issues, you can refer to [Hugging Face](https://huggingface.co/) or [PyTorch](https://pytorch.org/) for troubleshooting.
|