|
<p align="center"> |
|
<img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/nuhojubrps/banner.png" alt="BAGEL" width="480"/> |
|
</p> |
|
|
|
<p align="center"> |
|
<a href="https://bagel-ai.org/"> |
|
<img |
|
src="https://img.shields.io/badge/BAGEL-Website-0A66C2?logo=safari&logoColor=white" |
|
alt="BAGEL Website" |
|
/> |
|
</a> |
|
<a href="https://arxiv.org/abs/2505.14683"> |
|
<img |
|
src="https://img.shields.io/badge/BAGEL-Paper-red?logo=arxiv&logoColor=red" |
|
alt="BAGEL Paper on arXiv" |
|
/> |
|
</a> |
|
<a href="https://huggingface.co/JiaxinGe/Diffusers-BAGEL"> |
|
<img |
|
src="https://img.shields.io/badge/BAGEL–Diffusers-FF6C37?logo=huggingface&logoColor=white" |
|
alt="BAGEL Diffusers Pipeline" |
|
/> |
|
</a> |
|
<a href="https://huggingface.co/ByteDance-Seed/BAGEL-7B-MoT"> |
|
<img |
|
src="https://img.shields.io/badge/BAGEL-Model-yellow?logo=huggingface&logoColor=yellow" |
|
alt="BAGEL Original Model" |
|
/> |
|
</a> |
|
<a href="https://demo.bagel-ai.org/"> |
|
<img |
|
src="https://img.shields.io/badge/BAGEL-Demo-blue?logo=googleplay&logoColor=blue" |
|
alt="BAGEL Demo" |
|
/> |
|
</a> |
|
</p> |
|
|
|
# BAGEL: Diffusers Integration |
|
|
|
This repository hosts the **BAGEL** custom pipeline for 🤗 Diffusers, enabling seamless text-to-image, image editing, and visual understanding tasks with the BAGEL model. |
|
|
|
## 🚀 Quick Start |
|
|
|
```python |
|
pipe = DiffusionPipeline.from_pretrained( |
|
"JiaxinGe/Diffusers-BAGEL", |
|
custom_pipeline="JiaxinGe/Diffusers-BAGEL", |
|
torch_dtype=torch.bfloat16, |
|
trust_remote_code=True |
|
) |
|
pipe = pipe.to("cuda:0") |
|
# (1) text→image |
|
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." |
|
out = pipe(text=prompt) |
|
print(out) |
|
out['images'][0].save("bagel_text2img.png") |
|
|
|
# 2) text→image with “think” |
|
out = pipe( |
|
text="a car made of small cars", |
|
think=True |
|
) |
|
print(out['text']) |
|
out['images'][0].save("bagel_text2img_think.png") |
|
|
|
# 3) image editing |
|
from PIL import Image |
|
img = Image.open("~/Bagel/test_images/women.jpg") |
|
out = pipe( |
|
image=img, |
|
text="She boards a modern subway, quietly reading a folded newspaper…" |
|
) |
|
out['images'][0].save("bagel_img_edit.png") |
|
|
|
# 4) image editing + think |
|
img = Image.open("~/Bagel/test_images/octupusy.jpg") |
|
out = pipe( |
|
image=img, |
|
text="Could you display the sculpture that takes after this design?", |
|
think=True |
|
) |
|
print(out['text']) |
|
out['images'][0].save("bagel_img_edit_think.png") |
|
|
|
# 4) image understanding |
|
meme = Image.open("~/Bagel/test_images/meme.jpg") |
|
out = pipe( |
|
image=meme, |
|
text="Can someone explain what’s funny about this meme?", |
|
understanding_output=True |
|
) |
|
print(out['text']) |
|
``` |
|
|
|
## 🔧 Inference Hyperparameters |
|
|
|
* `cfg_text_scale`: text guidance strength (typical: 4.0–8.0) |
|
* `cfg_image_scale`: image guidance strength (1.0–2.0) |
|
* `cfg_interval`: fraction of steps to apply CFG (e.g. 0.4–1.0) |
|
* `num_timesteps`: total denoising steps (e.g. 50) |
|
* `timestep_shift`: offset of denoising schedule |
|
* `cfg_renorm_min` / `cfg_renorm_type`: renormalization settings for CFG |
|
|
|
For detailed explanations, see the original [BAGEL](https://github.com/bytedance-seed/BAGEL) repository. |
|
|