/luna

text to image generation with stable diffusion using tensorflow

Primary LanguagePythonMIT LicenseMIT

luna

luna_banner

This image background generated with stable diffusion luna

code_quality_checking python_post_processing TensorFlow

Stable diffusion is a deep learning, text-to-image model and used to generate detailted images conditioned on text description, thout it can also be applied to other task such as inpainting or outpainting and generate image to image translate guide by text prompt.

try online on google colab:

luna can running on online colab notebook you can check here:

usage for online colab:

  • click the connect

    connect

  • open on runtime and click run all ( ctrl+f9 if using shortcut )

    running

  • online collab running luna

usage

use venv

//create venv
python3 -m venv venv

//activate venv
source venv/bin/activate

clone repo

clone on https :

git clone https://github.com/slowy07/luna
cd luna
pip install -r requirements.txt

clone on ssh :

git clone git@github.com:slowy07/luna.git
cd luna
pip install -r requirements.txt

note : if using mac m1 you can try installing the requirements_m1.txt

run script

python text2image.py --prompt="example text"

to change the output file name run using the --output flag

python text2image.py --prompt="cool picture" --output="cool_pic.png"

install as python package

pip install git+https://github.com/slowy07/luna

and run the package using

from stable_diffusion_tensorflow.stable_diffusion import Text2Image

generator = Text2Image(img_height=512, img_width=512, jit_compose=False)
img = generator.generate(
  "DSLR photograph of an astronut riding a horse",
  num_steps = 50,
  unconditional_guidance_scale = 75,
  temperature = 1,
  batch_size = 1,
)

you can change dimension of image by change the img_height and img_width

generator = Text2Image(
  img_height = 1020 # or change 1080
  img_height = 1080 # or change 800
)

⚠️ NOTE ⚠️

if pip encountered an issue, try running pip with higher privilege using sudo

output

img = generator.generate(
  "DSLR photograph of an astronut riding a horse",
  num_steps = 50,
  unconditional_guidance_scale = 75,
  temperature = 1,
  batch_size = 1,
)

output:

description image
prompt: DSLR photograph of an astronut riding a horse astronut_horse
prompt: DSLR photograph of an astronut riding a horse with unconditional_guidance_scale 7.5 astronaut_horse2
prompt: DSLR photograph of an astronut riding a horse with unconditional_guidance_scale 7.5 astronaut_horse3
prompt: DSLR photograph of an astronut riding a horse with unconditional_guidance_scale 7.5 astronaut_horse4

other output

image_prompt: str = "Harry potter playing basketball"
img = generator.generate(
  image_prompt,
  num_steps = 50,
  unconditional_guidance_scale = 5.6,
  temperature = 1,
  batch_size = 1,
)
description image
prompt: indonesia country with cyberpunk style indonesia_country_with_cyberpunk_style
prompt: 3d detailed woman knight 3d_woman_knight
prompt: 3d detailed woman knight (next generation process) 3d_woman_knight2
prompt: 3d detailed woman knight (next generation process) 3d_woman_knight3
prompt: 3d detailed woman knight (next generation process) 3d_woman_knight4
prompt: realistic detailed knight realistic_detailed_knight
prompt: aesthetic art haunted house aesthetic_art_haunted_house
prompt: medival castle realistic and detailed oil painting medival_castle_realistic_and_detailed_oil_painting
prompt: harry potter playing basketball harry_potter_playing_basketball
prompt: harry potter playing guitar harry_potter_playing_guitar
prompt: person hacking with computer person_hacking_with_computer
prompt: God wearing mask god_wearing_mask
prompt: Harry potter random harry_potter_random
prompt: Marilyn monroe with random art style marilyn_monroe_with_random_art_style

donate

"Buy Me A Coffee"