Spaces:
Runtime error
Runtime error
File size: 5,657 Bytes
7fc5f26 a93d065 7fc5f26 a93d065 7fc5f26 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
import shutil
import gradio as gr
import torch
from diffusers import PixArtAlphaPipeline
import wandb
from wandb.integration.diffusers import autolog
pipeline = PixArtAlphaPipeline.from_pretrained(
"PixArt-alpha/PixArt-XL-2-1024-MS", torch_dtype=torch.float16
)
pipeline.enable_model_cpu_offload()
def generate_image(
wandb_project,
wandb_api_key,
prompt,
negative_prompt,
height,
width,
num_inference_steps,
guidance_scale,
seed,
):
if not (wandb_api_key is None or wandb_api_key == ""):
wandb.login(key=wandb_api_key, relogin=True)
generator = torch.Generator(device="cuda").manual_seed(seed)
autolog(init=dict(project=wandb_project))
run_url = wandb.run.get_url()
image = pipeline(
prompt,
negative_prompt=negative_prompt,
generator=generator,
height=height,
width=width,
guidance_scale=guidance_scale,
num_inference_steps=num_inference_steps,
).images[0]
wandb.finish()
if torch.cuda.is_available():
torch.cuda.empty_cache()
shutil.rmtree("wandb")
return image, f"**WandB Run:** [{run_url}]({run_url})"
else:
return (
None,
"A WandB API key is required to run this app! You can get one from [https://wandb.ai/authorize](https://wandb.ai/authorize)",
)
gr.Interface(
fn=generate_image,
inputs=[
gr.Textbox(label="WandB Project Name", value="pixart-alpha"),
gr.Textbox(
label="WandB API Key (You can get one from https://wandb.ai/authorize)",
type="password",
value=None,
),
gr.Textbox(
label="Prompt",
lines=3,
value="A dog that has been meditating all the time",
),
gr.Textbox(
label="Negative Prompt",
lines=3,
value="",
),
gr.Slider(minimum=512, maximum=1024, value=1024, step=128, label="Height"),
gr.Slider(minimum=512, maximum=1024, value=1024, step=128, label="Width"),
gr.Slider(
minimum=10,
maximum=100,
value=25,
step=10,
label="Number of Inference Steps",
),
gr.Slider(
minimum=1.0,
maximum=15.0,
value=4.5,
step=0.25,
label="Guidance Scale (How Closely the model follows the Prompt)",
),
gr.Slider(
minimum=0, step=1, maximum=999999999999999999, randomize=True, label="Seed"
),
],
outputs=["image", "markdown"],
title="Reproducible Pixart-α with WandB",
description="""
This space enables us to generate images using Pixart-α and track your experiments using Weights & Biases. In order to learn more about how Pixart-α was trained and how to make your experiments reproducible using [Weights & Biases](https://wandb.ai/site), check out [this report](https://wandb.ai/geekyrakshit/pixart-alpha/reports/PIXART-A-Diffusion-Transformer-Model-for-Text-to-Image-Generation--Vmlldzo2MTE1NzM3).
This app is powered by [🤗 Diffusers](https://huggingface.co/docs/diffusers) and [Weights & Biases](https://wandb.ai/site). A **Weights & Biases API key is necessary** to run this app, which you can find at **[https://wandb.ai/authorize](https://wandb.ai/authorize)**.
""",
examples=[
[
"pixart-alpha",
None,
"A dog that has been meditating all the time",
"",
1024,
1024,
25,
4.5,
256174057,
],
[
"pixart-alpha",
None,
"poster of a mechanical cat, technical Schematics viewed from front and side view on light white blueprint paper, illustration drafting style, illustration, typography, conceptual art, dark fantasy steampunk, cinematic, dark fantasy.",
"",
1024,
1024,
25,
4.5,
256174057,
],
[
"pixart-alpha",
None,
"Art collection style and fashion shoot, in the style of made of glass, dark blue and light pink, paulrand, solarpunk, camillevivier, bethdidonatohair, barbiecore, hyper-realistic.",
"",
1024,
1024,
25,
4.5,
256174057,
],
[
"pixart-alpha",
None,
"Oppenheimer sits on the beach on a chair, watching a nuclear exposition with a huge mushroom cloud, 120mm",
"",
1024,
1024,
25,
4.5,
256174057,
],
[
"pixart-alpha",
None,
"a Emu, focused yet playful, ready for a competitive matchup, photorealistic quality with cartoon vibes",
"",
1024,
1024,
25,
4.5,
256174057,
],
[
"pixart-alpha",
None,
"a traveler navigating via a boat in countless mountains, Chinese ink painting",
"",
1024,
1024,
25,
4.5,
256174057,
],
[
"pixart-alpha",
None,
"paper artwork, layered paper, colorful Chinese dragon surrounded by clouds",
"",
1024,
1024,
25,
4.5,
256174057,
],
],
).launch(debug=True, max_threads=80) |