├── README.md
├── style_aligned_4x_gradio_colab.ipynb
└── style_aligned_gradio_colab.ipynb
/README.md:
--------------------------------------------------------------------------------
1 | 🐣 Please follow me for new updates https://twitter.com/camenduru
2 | 🔥 Please join our discord server https://discord.gg/k5BwmmvJJU
3 | 🥳 Please join my patreon community https://patreon.com/camenduru
4 |
5 | # 🚦 WIP 🚦
6 |
7 | ## 🦒 Colab
8 |
9 | | Colab | Info
10 | | --- | --- |
11 | [](https://colab.research.google.com/github/camenduru/style-aligned-colab/blob/main/style_aligned_gradio_colab.ipynb) | style_aligned_gradio_colab
12 | [](https://colab.research.google.com/github/camenduru/style-aligned-colab/blob/main/style_aligned_4x_gradio_colab.ipynb) | style_aligned_4x_gradio_colab (Pro Colab 😭)
13 |
14 | ## Main Repo
15 | https://github.com/google/style-aligned
16 |
17 | ## Paper
18 | https://arxiv.org/abs/2312.02133
19 | https://style-aligned-gen.github.io/data/StyleAligned.pdf
20 |
21 | ## Page
22 | https://style-aligned-gen.github.io/
23 |
24 | ## Output
25 | 
26 |
27 | ## Sponsor
28 | https://modelslab.com
29 |
--------------------------------------------------------------------------------
/style_aligned_4x_gradio_colab.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "view-in-github"
7 | },
8 | "source": [
9 | "[](https://colab.research.google.com/github/camenduru/style-aligned-colab/blob/main/style_aligned_4x_gradio_colab.ipynb)"
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {
16 | "id": "VjYy0F2gZIPR"
17 | },
18 | "outputs": [],
19 | "source": [
20 | "!pip install -q diffusers transformers accelerate peft gradio==3.50.2 mediapy einops\n",
21 | "!pip install -q https://download.pytorch.org/whl/cu121/xformers-0.0.22.post7-cp310-cp310-manylinux2014_x86_64.whl\n",
22 | "\n",
23 | "%cd /content\n",
24 | "!git clone -b dev https://github.com/camenduru/style-aligned\n",
25 | "%cd /content/style-aligned\n",
26 | "\n",
27 | "from diffusers import StableDiffusionXLPipeline, DDIMScheduler\n",
28 | "import torch\n",
29 | "import mediapy\n",
30 | "import sa_handler\n",
31 | "\n",
32 | "scheduler = DDIMScheduler(beta_start=0.00085, beta_end=0.012, beta_schedule=\"scaled_linear\", clip_sample=False, set_alpha_to_one=False)\n",
33 | "pipeline = StableDiffusionXLPipeline.from_pretrained(\"stabilityai/stable-diffusion-xl-base-1.0\", torch_dtype=torch.float16, variant=\"fp16\", use_safetensors=True, scheduler=scheduler).to(\"cuda\")\n",
34 | "pipeline.enable_xformers_memory_efficient_attention()\n",
35 | "handler = sa_handler.Handler(pipeline)\n",
36 | "sa_args = sa_handler.StyleAlignedArgs(share_group_norm=False, share_layer_norm=False, share_attention=True, adain_queries=True, adain_keys=True, adain_values=False)\n",
37 | "handler.register(sa_args)\n",
38 | "\n",
39 | "import gradio as gr\n",
40 | "\n",
41 | "def generate(prompt1, prompt2, prompt3, prompt4, negative_prompt, num_inference_steps, width, height):\n",
42 | " sets_of_prompts = [prompt1, prompt2, prompt3, prompt4]\n",
43 | " images = pipeline(prompt=sets_of_prompts, negative_prompt=negative_prompt, width=width, height=height, num_inference_steps=num_inference_steps).images\n",
44 | " return images\n",
45 | "\n",
46 | "with gr.Blocks(title=f\"Style Aligned\", css=\".gradio-container {max-width: 850px !important}\") as demo:\n",
47 | " with gr.Group():\n",
48 | " prompt1 = gr.Textbox(show_label=False, value=\"a toy train. macro photo. 3d game asset\")\n",
49 | " prompt2 = gr.Textbox(show_label=False, value=\"a toy airplane. macro photo. 3d game asset\")\n",
50 | " prompt3 = gr.Textbox(show_label=False, value=\"a toy car. macro photo. 3d game asset\")\n",
51 | " prompt4 = gr.Textbox(show_label=False, value=\"a toy boat. macro photo. 3d game asset\")\n",
52 | " with gr.Row():\n",
53 | " negative_prompt = gr.Textbox(show_label=False, value=\"low-resolution\")\n",
54 | " button = gr.Button()\n",
55 | " with gr.Row():\n",
56 | " width = gr.Slider(minimum=256, maximum=2048, step=8, value=768, label=\"width\")\n",
57 | " height = gr.Slider(minimum=256, maximum=2048, step=8, value=768, label=\"height\")\n",
58 | " num_inference_steps = gr.Slider(minimum=1, maximum=150, step=1, value=50, label=\"num_inference_steps\")\n",
59 | " output_images = gr.Gallery(\n",
60 | " show_label=False,\n",
61 | " type=\"pil\",\n",
62 | " interactive=False,\n",
63 | " height=816,\n",
64 | " width=816,\n",
65 | " elem_id=\"output_image\",\n",
66 | " )\n",
67 | " button.click(fn=generate, inputs=[prompt1, prompt2, prompt3, prompt4, negative_prompt, num_inference_steps, width, height], outputs=[output_images], show_progress=True)\n",
68 | "demo.queue().launch(inline=False, share=True, debug=True)"
69 | ]
70 | }
71 | ],
72 | "metadata": {
73 | "accelerator": "GPU",
74 | "colab": {
75 | "gpuType": "T4",
76 | "provenance": []
77 | },
78 | "kernelspec": {
79 | "display_name": "Python 3",
80 | "name": "python3"
81 | },
82 | "language_info": {
83 | "name": "python"
84 | }
85 | },
86 | "nbformat": 4,
87 | "nbformat_minor": 0
88 | }
89 |
--------------------------------------------------------------------------------
/style_aligned_gradio_colab.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "view-in-github"
7 | },
8 | "source": [
9 | "[](https://colab.research.google.com/github/camenduru/style-aligned-colab/blob/main/style_aligned_gradio_colab.ipynb)"
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {
16 | "id": "VjYy0F2gZIPR"
17 | },
18 | "outputs": [],
19 | "source": [
20 | "!pip install -q diffusers transformers accelerate peft gradio==3.50.2 mediapy einops\n",
21 | "!pip install -q https://download.pytorch.org/whl/cu121/xformers-0.0.22.post7-cp310-cp310-manylinux2014_x86_64.whl\n",
22 | "\n",
23 | "%cd /content\n",
24 | "!git clone -b dev https://github.com/camenduru/style-aligned\n",
25 | "%cd /content/style-aligned\n",
26 | "\n",
27 | "from diffusers import StableDiffusionXLPipeline, DDIMScheduler\n",
28 | "import torch\n",
29 | "import mediapy\n",
30 | "import sa_handler\n",
31 | "\n",
32 | "scheduler = DDIMScheduler(beta_start=0.00085, beta_end=0.012, beta_schedule=\"scaled_linear\", clip_sample=False, set_alpha_to_one=False)\n",
33 | "pipeline = StableDiffusionXLPipeline.from_pretrained(\"stabilityai/stable-diffusion-xl-base-1.0\", torch_dtype=torch.float16, variant=\"fp16\", use_safetensors=True, scheduler=scheduler).to(\"cuda\")\n",
34 | "pipeline.enable_xformers_memory_efficient_attention()\n",
35 | "handler = sa_handler.Handler(pipeline)\n",
36 | "sa_args = sa_handler.StyleAlignedArgs(share_group_norm=False, share_layer_norm=False, share_attention=True, adain_queries=True, adain_keys=True, adain_values=False)\n",
37 | "handler.register(sa_args)\n",
38 | "\n",
39 | "import gradio as gr\n",
40 | "\n",
41 | "def generate(prompt1, prompt2, negative_prompt, num_inference_steps, width, height):\n",
42 | " sets_of_prompts = [prompt1, prompt2]\n",
43 | " images = pipeline(prompt=sets_of_prompts, negative_prompt=negative_prompt, width=width, height=height, num_inference_steps=num_inference_steps).images\n",
44 | " return images\n",
45 | "\n",
46 | "with gr.Blocks(title=f\"Style Aligned\", css=\".gradio-container {max-width: 850px !important}\") as demo:\n",
47 | " with gr.Group():\n",
48 | " prompt1 = gr.Textbox(show_label=False, value=\"a toy train. macro photo. 3d game asset\")\n",
49 | " prompt2 = gr.Textbox(show_label=False, value=\"a toy airplane. macro photo. 3d game asset\")\n",
50 | " with gr.Row():\n",
51 | " negative_prompt = gr.Textbox(show_label=False, value=\"low-resolution\")\n",
52 | " button = gr.Button()\n",
53 | " with gr.Row():\n",
54 | " width = gr.Slider(minimum=256, maximum=2048, step=8, value=768, label=\"width\")\n",
55 | " height = gr.Slider(minimum=256, maximum=2048, step=8, value=768, label=\"height\")\n",
56 | " num_inference_steps = gr.Slider(minimum=1, maximum=150, step=1, value=50, label=\"num_inference_steps\")\n",
57 | " output_images = gr.Gallery(\n",
58 | " show_label=False,\n",
59 | " type=\"pil\",\n",
60 | " interactive=False,\n",
61 | " height=816,\n",
62 | " width=816,\n",
63 | " elem_id=\"output_image\",\n",
64 | " )\n",
65 | " button.click(fn=generate, inputs=[prompt1, prompt2, negative_prompt, num_inference_steps, width, height], outputs=[output_images], show_progress=True)\n",
66 | "demo.queue().launch(inline=False, share=True, debug=True)"
67 | ]
68 | }
69 | ],
70 | "metadata": {
71 | "accelerator": "GPU",
72 | "colab": {
73 | "gpuType": "T4",
74 | "provenance": []
75 | },
76 | "kernelspec": {
77 | "display_name": "Python 3",
78 | "name": "python3"
79 | },
80 | "language_info": {
81 | "name": "python"
82 | }
83 | },
84 | "nbformat": 4,
85 | "nbformat_minor": 0
86 | }
87 |
--------------------------------------------------------------------------------