geekyrakshit's picture
update: application + dependencies
a93d065
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)