Update README.md
Browse files
README.md
CHANGED
|
@@ -2,4 +2,36 @@
|
|
| 2 |
license: mit
|
| 3 |
base_model:
|
| 4 |
- stabilityai/sdxl-turbo
|
| 5 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
license: mit
|
| 3 |
base_model:
|
| 4 |
- stabilityai/sdxl-turbo
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
**Use with the Stable Diffusion Pipeline**
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
```python
|
| 11 |
+
import torch
|
| 12 |
+
from diffusers import AutoPipelineForText2Image
|
| 13 |
+
from transformers import CLIPTokenizer, CLIPTextModel
|
| 14 |
+
|
| 15 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 16 |
+
lang = "hin_Deva" # Hindi
|
| 17 |
+
|
| 18 |
+
# Load pipeline
|
| 19 |
+
pipe = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo")
|
| 20 |
+
|
| 21 |
+
# Load the multilingual tokenizer
|
| 22 |
+
tokenizer = CLIPTokenizer.from_pretrained("tokenizers/multilingual")
|
| 23 |
+
pipe.tokenizer = tokenizer
|
| 24 |
+
pipe.text_encoder.resize_token_embeddings(len(tokenizer))
|
| 25 |
+
|
| 26 |
+
# Load the fine-tuned text encoder
|
| 27 |
+
state_dict = torch.load(f"models/{lang}/{lang}_text_encoder.pth")
|
| 28 |
+
new_text_encoder = CLIPTextModel(config=pipe.text_encoder.config)
|
| 29 |
+
new_text_encoder.load_state_dict(state_dict)
|
| 30 |
+
new_text_encoder = new_text_encoder.to(device)
|
| 31 |
+
pipe.text_encoder = new_text_encoder
|
| 32 |
+
pipe = pipe.to(device)
|
| 33 |
+
|
| 34 |
+
# Generate and save image
|
| 35 |
+
caption = "हिंदी गाँव का शांतिपूर्ण दृश्य, पारंपरिक शैली में"
|
| 36 |
+
image = pipe(caption).images[0]
|
| 37 |
+
image.save(f"example.png")
|