Spaces:
Runtime error
Runtime error
geekyrakshit
commited on
Commit
•
7fc5f26
1
Parent(s):
427e432
add: app.py + dependencies
Browse files- app.py +179 -0
- requirements.txt +8 -0
app.py
ADDED
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import shutil
|
3 |
+
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
import torch
|
7 |
+
from diffusers import PixArtAlphaPipeline
|
8 |
+
|
9 |
+
import wandb
|
10 |
+
from wandb.integration.diffusers import autolog
|
11 |
+
|
12 |
+
|
13 |
+
pipeline = PixArtAlphaPipeline.from_pretrained(
|
14 |
+
"PixArt-alpha/PixArt-XL-2-1024-MS", torch_dtype=torch.float16
|
15 |
+
)
|
16 |
+
pipeline.enable_model_cpu_offload()
|
17 |
+
|
18 |
+
|
19 |
+
def generate_image(
|
20 |
+
wandb_project,
|
21 |
+
wandb_api_key,
|
22 |
+
prompt,
|
23 |
+
negative_prompt,
|
24 |
+
height,
|
25 |
+
width,
|
26 |
+
num_inference_steps,
|
27 |
+
guidance_scale,
|
28 |
+
seed,
|
29 |
+
):
|
30 |
+
if not (wandb_api_key is None or wandb_api_key == ""):
|
31 |
+
os.environ["WANDB_API_KEY"] = wandb_api_key
|
32 |
+
generator = torch.Generator(device="cuda").manual_seed(seed)
|
33 |
+
autolog(init=dict(project=wandb_project))
|
34 |
+
run_url = wandb.run.get_url()
|
35 |
+
image = pipeline(
|
36 |
+
prompt,
|
37 |
+
negative_prompt=negative_prompt,
|
38 |
+
generator=generator,
|
39 |
+
height=height,
|
40 |
+
width=width,
|
41 |
+
guidance_scale=guidance_scale,
|
42 |
+
num_inference_steps=num_inference_steps,
|
43 |
+
).images[0]
|
44 |
+
if torch.cuda.is_available():
|
45 |
+
torch.cuda.empty_cache()
|
46 |
+
shutil.rmtree("wandb")
|
47 |
+
return image, f"**WandB Run:** [{run_url}]({run_url})"
|
48 |
+
else:
|
49 |
+
return (
|
50 |
+
None,
|
51 |
+
"A WandB API key is required to run this app! You can get one from [https://wandb.ai/authorize](https://wandb.ai/authorize)",
|
52 |
+
)
|
53 |
+
|
54 |
+
|
55 |
+
gr.Interface(
|
56 |
+
fn=generate_image,
|
57 |
+
inputs=[
|
58 |
+
gr.Textbox(label="WandB Project Name", value="pixart-alpha"),
|
59 |
+
gr.Textbox(
|
60 |
+
label="WandB API Key (You can get one from https://wandb.ai/authorize)",
|
61 |
+
type="password",
|
62 |
+
value=None,
|
63 |
+
),
|
64 |
+
gr.Textbox(
|
65 |
+
label="Prompt",
|
66 |
+
lines=3,
|
67 |
+
value="A dog that has been meditating all the time",
|
68 |
+
),
|
69 |
+
gr.Textbox(
|
70 |
+
label="Negative Prompt",
|
71 |
+
lines=3,
|
72 |
+
value="",
|
73 |
+
),
|
74 |
+
gr.Slider(minimum=512, maximum=1024, value=1024, step=128, label="Height"),
|
75 |
+
gr.Slider(minimum=512, maximum=1024, value=1024, step=128, label="Width"),
|
76 |
+
gr.Slider(
|
77 |
+
minimum=10,
|
78 |
+
maximum=100,
|
79 |
+
value=25,
|
80 |
+
step=10,
|
81 |
+
label="Number of Inference Steps",
|
82 |
+
),
|
83 |
+
gr.Slider(
|
84 |
+
minimum=1.0,
|
85 |
+
maximum=15.0,
|
86 |
+
value=4.5,
|
87 |
+
step=0.25,
|
88 |
+
label="Guidance Scale (How Closely the model follows the Prompt)",
|
89 |
+
),
|
90 |
+
gr.Slider(
|
91 |
+
minimum=0, step=1, maximum=999999999999999999, randomize=True, label="Seed"
|
92 |
+
),
|
93 |
+
],
|
94 |
+
outputs=["image", "markdown"],
|
95 |
+
title="Reproducible Pixart-α with WandB",
|
96 |
+
description="""
|
97 |
+
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).
|
98 |
+
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)**.
|
99 |
+
""",
|
100 |
+
examples=[
|
101 |
+
[
|
102 |
+
"pixart-alpha",
|
103 |
+
None,
|
104 |
+
"A dog that has been meditating all the time",
|
105 |
+
"",
|
106 |
+
1024,
|
107 |
+
1024,
|
108 |
+
25,
|
109 |
+
4.5,
|
110 |
+
256174057,
|
111 |
+
],
|
112 |
+
[
|
113 |
+
"pixart-alpha",
|
114 |
+
None,
|
115 |
+
"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.",
|
116 |
+
"",
|
117 |
+
1024,
|
118 |
+
1024,
|
119 |
+
25,
|
120 |
+
4.5,
|
121 |
+
256174057,
|
122 |
+
],
|
123 |
+
[
|
124 |
+
"pixart-alpha",
|
125 |
+
None,
|
126 |
+
"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.",
|
127 |
+
"",
|
128 |
+
1024,
|
129 |
+
1024,
|
130 |
+
25,
|
131 |
+
4.5,
|
132 |
+
256174057,
|
133 |
+
],
|
134 |
+
[
|
135 |
+
"pixart-alpha",
|
136 |
+
None,
|
137 |
+
"Oppenheimer sits on the beach on a chair, watching a nuclear exposition with a huge mushroom cloud, 120mm",
|
138 |
+
"",
|
139 |
+
1024,
|
140 |
+
1024,
|
141 |
+
25,
|
142 |
+
4.5,
|
143 |
+
256174057,
|
144 |
+
],
|
145 |
+
[
|
146 |
+
"pixart-alpha",
|
147 |
+
None,
|
148 |
+
"a Emu, focused yet playful, ready for a competitive matchup, photorealistic quality with cartoon vibes",
|
149 |
+
"",
|
150 |
+
1024,
|
151 |
+
1024,
|
152 |
+
25,
|
153 |
+
4.5,
|
154 |
+
256174057,
|
155 |
+
],
|
156 |
+
[
|
157 |
+
"pixart-alpha",
|
158 |
+
None,
|
159 |
+
"a traveler navigating via a boat in countless mountains, Chinese ink painting",
|
160 |
+
"",
|
161 |
+
1024,
|
162 |
+
1024,
|
163 |
+
25,
|
164 |
+
4.5,
|
165 |
+
256174057,
|
166 |
+
],
|
167 |
+
[
|
168 |
+
"pixart-alpha",
|
169 |
+
None,
|
170 |
+
"paper artwork, layered paper, colorful Chinese dragon surrounded by clouds",
|
171 |
+
"",
|
172 |
+
1024,
|
173 |
+
1024,
|
174 |
+
25,
|
175 |
+
4.5,
|
176 |
+
256174057,
|
177 |
+
],
|
178 |
+
],
|
179 |
+
).launch(debug=True, max_threads=80)
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
transformers
|
3 |
+
diffusers
|
4 |
+
accelerate
|
5 |
+
torch
|
6 |
+
ftfy
|
7 |
+
sentencepiece
|
8 |
+
wandb @ git+https://github.com/wandb/wandb@main
|