bagel
Browse files
README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<p align="center">
|
| 2 |
+
<img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/nuhojubrps/banner.png" alt="BAGEL" width="480"/>
|
| 3 |
+
</p>
|
| 4 |
+
|
| 5 |
+
<p align="center">
|
| 6 |
+
<a href="https://bagel-ai.org/">
|
| 7 |
+
<img
|
| 8 |
+
src="https://img.shields.io/badge/BAGEL-Website-0A66C2?logo=safari&logoColor=white"
|
| 9 |
+
alt="BAGEL Website"
|
| 10 |
+
/>
|
| 11 |
+
</a>
|
| 12 |
+
<a href="https://arxiv.org/abs/2505.14683">
|
| 13 |
+
<img
|
| 14 |
+
src="https://img.shields.io/badge/BAGEL-Paper-red?logo=arxiv&logoColor=red"
|
| 15 |
+
alt="BAGEL Paper on arXiv"
|
| 16 |
+
/>
|
| 17 |
+
</a>
|
| 18 |
+
<a href="https://huggingface.co/JiaxinGe/Diffusers-BAGEL">
|
| 19 |
+
<img
|
| 20 |
+
src="https://img.shields.io/badge/BAGEL–Diffusers-FF6C37?logo=huggingface&logoColor=white"
|
| 21 |
+
alt="BAGEL Diffusers Pipeline"
|
| 22 |
+
/>
|
| 23 |
+
</a>
|
| 24 |
+
<a href="https://huggingface.co/ByteDance-Seed/BAGEL-7B-MoT">
|
| 25 |
+
<img
|
| 26 |
+
src="https://img.shields.io/badge/BAGEL-Model-yellow?logo=huggingface&logoColor=yellow"
|
| 27 |
+
alt="BAGEL Original Model"
|
| 28 |
+
/>
|
| 29 |
+
</a>
|
| 30 |
+
<a href="https://demo.bagel-ai.org/">
|
| 31 |
+
<img
|
| 32 |
+
src="https://img.shields.io/badge/BAGEL-Demo-blue?logo=googleplay&logoColor=blue"
|
| 33 |
+
alt="BAGEL Demo"
|
| 34 |
+
/>
|
| 35 |
+
</a>
|
| 36 |
+
</p>
|
| 37 |
+
|
| 38 |
+
# BAGEL: Diffusers Integration
|
| 39 |
+
|
| 40 |
+
This repository hosts the **BAGEL** custom pipeline for 🤗 Diffusers, enabling seamless text-to-image, image editing, and visual understanding tasks with the BAGEL model.
|
| 41 |
+
|
| 42 |
+
## 🚀 Quick Start
|
| 43 |
+
|
| 44 |
+
```python
|
| 45 |
+
pipe = DiffusionPipeline.from_pretrained(
|
| 46 |
+
"JiaxinGe/Diffusers-BAGEL",
|
| 47 |
+
custom_pipeline="JiaxinGe/Diffusers-BAGEL",
|
| 48 |
+
torch_dtype=torch.bfloat16,
|
| 49 |
+
trust_remote_code=True
|
| 50 |
+
)
|
| 51 |
+
pipe = pipe.to("cuda:0")
|
| 52 |
+
# (1) text→image
|
| 53 |
+
prompt = "A female cosplayer portraying an ethereal fairy or elf, wearing a flowing dress made of delicate fabrics in soft, mystical colors like emerald green and silver. She has pointed ears, a gentle, enchanting expression, and her outfit is adorned with sparkling jewels and intricate patterns. The background is a magical forest with glowing plants, mystical creatures, and a serene atmosphere."
|
| 54 |
+
out = pipe(text=prompt)
|
| 55 |
+
print(out)
|
| 56 |
+
out['images'][0].save("bagel_text2img.png")
|
| 57 |
+
|
| 58 |
+
# 2) text→image with “think”
|
| 59 |
+
out = pipe(
|
| 60 |
+
text="a car made of small cars",
|
| 61 |
+
think=True
|
| 62 |
+
)
|
| 63 |
+
print(out['text'])
|
| 64 |
+
out['images'][0].save("bagel_text2img_think.png")
|
| 65 |
+
|
| 66 |
+
# 3) image editing
|
| 67 |
+
from PIL import Image
|
| 68 |
+
img = Image.open("~/Bagel/test_images/women.jpg")
|
| 69 |
+
out = pipe(
|
| 70 |
+
image=img,
|
| 71 |
+
text="She boards a modern subway, quietly reading a folded newspaper…"
|
| 72 |
+
)
|
| 73 |
+
out['images'][0].save("bagel_img_edit.png")
|
| 74 |
+
|
| 75 |
+
# 4) image editing + think
|
| 76 |
+
img = Image.open("~/Bagel/test_images/octupusy.jpg")
|
| 77 |
+
out = pipe(
|
| 78 |
+
image=img,
|
| 79 |
+
text="Could you display the sculpture that takes after this design?",
|
| 80 |
+
think=True
|
| 81 |
+
)
|
| 82 |
+
print(out['text'])
|
| 83 |
+
out['images'][0].save("bagel_img_edit_think.png")
|
| 84 |
+
|
| 85 |
+
# 4) image understanding
|
| 86 |
+
meme = Image.open("~/Bagel/test_images/meme.jpg")
|
| 87 |
+
out = pipe(
|
| 88 |
+
image=meme,
|
| 89 |
+
text="Can someone explain what’s funny about this meme?",
|
| 90 |
+
understanding_output=True
|
| 91 |
+
)
|
| 92 |
+
print(out['text'])
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
## 🔧 Inference Hyperparameters
|
| 96 |
+
|
| 97 |
+
* `cfg_text_scale`: text guidance strength (typical: 4.0–8.0)
|
| 98 |
+
* `cfg_image_scale`: image guidance strength (1.0–2.0)
|
| 99 |
+
* `cfg_interval`: fraction of steps to apply CFG (e.g. 0.4–1.0)
|
| 100 |
+
* `num_timesteps`: total denoising steps (e.g. 50)
|
| 101 |
+
* `timestep_shift`: offset of denoising schedule
|
| 102 |
+
* `cfg_renorm_min` / `cfg_renorm_type`: renormalization settings for CFG
|
| 103 |
+
|
| 104 |
+
For detailed explanations, see the original [BAGEL](https://github.com/bytedance-seed/BAGEL) repository.
|