Skip to content

Yazdi9/TextToImage

Repository files navigation

Open In Colab

Output Output Output
"A group of adorable animals having a picnic in a sunny meadow, including a bunny, a squirrel, a fox, and a hedgehog, with a colorful blanket and baskets of fruit" "A beautifully manicured Victorian garden with blooming flowers, elegant statues, and a grand fountain in the center, under a bright blue sky" "A friendly robot companion walking alongside a child in a park, with blooming flowers and a beautiful sunset in the background"
"An old, enchanted library with towering bookshelves, floating books, and a cozy reading nook with a fireplace casting a warm glow" "A picturesque winter wonderland with snow-covered trees, a frozen lake, and a cozy cabin with smoke curling from the chimney" "A serene, mystical forest with bioluminescent plants glowing in various colors under a starry night sky."
"A grand fantasy castle perched on a cliff, with turrets and spires reaching into the clouds, surrounded by a magical, swirling mist" "An astronaut standing on the surface of a distant planet, looking out at a stunning galaxy filled with stars, nebulae, and a nearby spaceship" "A vibrant alien landscape with strange, colorful plants, unusual rock formations, and a sky with multiple moons and planets visible"

🔥 (Text-to-Image):

To run the model locally, you can download the "local_gradio" folder:

  1. Install Pytorch (CUDA). MacOS system can download the "MPS" version of Pytorch. Please refer to: https://pytorch.org. Install Intel Extension for Pytorch as well if you're using Intel GPUs.
  2. Install the main library:
pip install diffusers transformers accelerate gradio==3.48.0 
  1. Launch the gradio: (For MacOS users, need to set the device="mps" in app.py; For Intel GPU users, set device="xpu" in app.py)
python app.py

LCM Model Download: LCM_Dreamshaper_v7

By distilling classifier-free guidance into the model's input, LCM can generate high-quality images in very short inference time. We compare the inference time at the setting of 768 x 768 resolution, CFG scale w=8, batchsize=4, using a A800 GPU.

Usage

To run the model yourself, you can leverage the 🧨 Diffusers library:

  1. Install the library:
pip install --upgrade diffusers  # make sure to use at least diffusers >= 0.22
pip install transformers accelerate
  1. Run the model:
from diffusers import DiffusionPipeline
import torch

pipe = DiffusionPipeline.from_pretrained("SimianLuo/LCM_Dreamshaper_v7")

# To save GPU memory, torch.float16 can be used, but it may compromise image quality.
pipe.to(torch_device="cuda", torch_dtype=torch.float32)

prompt = "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k"

# Can be set to 1~50 steps. LCM support fast inference even <= 4 steps. Recommend: 1~8 steps.
num_inference_steps = 4 

images = pipe(prompt=prompt, num_inference_steps=num_inference_steps, guidance_scale=8.0, lcm_origin_steps=50, output_type="pil").images