justinpinkney commited on
Commit
f8604b5
0 Parent(s):

initial commit

Browse files
Files changed (4) hide show
  1. .gitattributes +31 -0
  2. README.md +12 -0
  3. app.py +202 -0
  4. requirements.txt +7 -0
.gitattributes ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ftz filter=lfs diff=lfs merge=lfs -text
6
+ *.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.h5 filter=lfs diff=lfs merge=lfs -text
8
+ *.joblib filter=lfs diff=lfs merge=lfs -text
9
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
10
+ *.model filter=lfs diff=lfs merge=lfs -text
11
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
12
+ *.npy filter=lfs diff=lfs merge=lfs -text
13
+ *.npz filter=lfs diff=lfs merge=lfs -text
14
+ *.onnx filter=lfs diff=lfs merge=lfs -text
15
+ *.ot filter=lfs diff=lfs merge=lfs -text
16
+ *.parquet filter=lfs diff=lfs merge=lfs -text
17
+ *.pickle filter=lfs diff=lfs merge=lfs -text
18
+ *.pkl filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pt filter=lfs diff=lfs merge=lfs -text
21
+ *.pth filter=lfs diff=lfs merge=lfs -text
22
+ *.rar filter=lfs diff=lfs merge=lfs -text
23
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
24
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
25
+ *.tflite filter=lfs diff=lfs merge=lfs -text
26
+ *.tgz filter=lfs diff=lfs merge=lfs -text
27
+ *.wasm filter=lfs diff=lfs merge=lfs -text
28
+ *.xz filter=lfs diff=lfs merge=lfs -text
29
+ *.zip filter=lfs diff=lfs merge=lfs -text
30
+ *.zst filter=lfs diff=lfs merge=lfs -text
31
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Text to Pokémon
3
+ emoji: 🌖
4
+ colorFrom: purple
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 3.3.1
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from contextlib import nullcontext
2
+ import gradio as gr
3
+ import torch
4
+ from torch import autocast
5
+ from diffusers import StableDiffusionPipeline
6
+
7
+
8
+ device = "cuda" if torch.cuda.is_available() else "cpu"
9
+ context = autocast if device == "cuda" else nullcontext
10
+ dtype = torch.float16 if device == "cuda" else torch.float32
11
+
12
+ pipe = StableDiffusionPipeline.from_pretrained("lambdalabs/sd-pokemon-diffusers", torch_dtype=dtype)
13
+ pipe = pipe.to(device)
14
+
15
+
16
+ # Sometimes the nsfw checker is confused by the Pokémon images, you can disable
17
+ # it at your own risk here
18
+ disable_safety = True
19
+
20
+ if disable_safety:
21
+ def null_safety(images, **kwargs):
22
+ return images, False
23
+ pipe.safety_checker = null_safety
24
+
25
+
26
+ def infer(prompt, n_samples, steps, scale):
27
+
28
+ with context("cuda"):
29
+ images = pipe(n_samples*[prompt], guidance_scale=scale, num_inference_steps=steps).images
30
+
31
+ return images
32
+
33
+ css = """
34
+ a {
35
+ color: inherit;
36
+ text-decoration: underline;
37
+ }
38
+ .gradio-container {
39
+ font-family: 'IBM Plex Sans', sans-serif;
40
+ }
41
+ .gr-button {
42
+ color: white;
43
+ border-color: #9d66e5;
44
+ background: #9d66e5;
45
+ }
46
+ input[type='range'] {
47
+ accent-color: #9d66e5;
48
+ }
49
+ .dark input[type='range'] {
50
+ accent-color: #dfdfdf;
51
+ }
52
+ .container {
53
+ max-width: 730px;
54
+ margin: auto;
55
+ padding-top: 1.5rem;
56
+ }
57
+ #gallery {
58
+ min-height: 22rem;
59
+ margin-bottom: 15px;
60
+ margin-left: auto;
61
+ margin-right: auto;
62
+ border-bottom-right-radius: .5rem !important;
63
+ border-bottom-left-radius: .5rem !important;
64
+ }
65
+ #gallery>div>.h-full {
66
+ min-height: 20rem;
67
+ }
68
+ .details:hover {
69
+ text-decoration: underline;
70
+ }
71
+ .gr-button {
72
+ white-space: nowrap;
73
+ }
74
+ .gr-button:focus {
75
+ border-color: rgb(147 197 253 / var(--tw-border-opacity));
76
+ outline: none;
77
+ box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
78
+ --tw-border-opacity: 1;
79
+ --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
80
+ --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
81
+ --tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
82
+ --tw-ring-opacity: .5;
83
+ }
84
+ #advanced-options {
85
+ margin-bottom: 20px;
86
+ }
87
+ .footer {
88
+ margin-bottom: 45px;
89
+ margin-top: 35px;
90
+ text-align: center;
91
+ border-bottom: 1px solid #e5e5e5;
92
+ }
93
+ .footer>p {
94
+ font-size: .8rem;
95
+ display: inline-block;
96
+ padding: 0 10px;
97
+ transform: translateY(10px);
98
+ background: white;
99
+ }
100
+ .dark .footer {
101
+ border-color: #303030;
102
+ }
103
+ .dark .footer>p {
104
+ background: #0b0f19;
105
+ }
106
+ .acknowledgments h4{
107
+ margin: 1.25em 0 .25em 0;
108
+ font-weight: bold;
109
+ font-size: 115%;
110
+ }
111
+ """
112
+
113
+ block = gr.Blocks(css=css)
114
+
115
+ examples = [
116
+ [
117
+ 'Yoda',
118
+ 2,
119
+ 7.5,
120
+ ],
121
+ [
122
+ 'Abraham Lincoln',
123
+ 2,
124
+ 7.5,
125
+ ],
126
+ [
127
+ 'George Washington',
128
+ 2,
129
+ 7,
130
+ ],
131
+ ]
132
+
133
+ with block:
134
+ gr.HTML(
135
+ """
136
+ <div style="text-align: center; max-width: 650px; margin: 0 auto;">
137
+ <div>
138
+ <img src="https://lambdalabs.com/static/images/lambda-logo.svg" alt="Lambda Logo"
139
+ style="margin: auto; max-width: 7rem;">
140
+ <h1 style="font-weight: 900; font-size: 3rem;">
141
+ Pokémon text to image
142
+ </h1>
143
+ </div>
144
+ <p style="margin-bottom: 10px; font-size: 94%">
145
+ Generate new Pokémon from a text description,
146
+ <a href="https://lambdalabs.com/blog/how-to-fine-tune-stable-diffusion-how-we-made-the-text-to-pokemon-model-at-lambda/">created by Lambda Labs</a>.
147
+ </p>
148
+ </div>
149
+ """
150
+ )
151
+ with gr.Group():
152
+ with gr.Box():
153
+ with gr.Row().style(mobile_collapse=False, equal_height=True):
154
+ text = gr.Textbox(
155
+ label="Enter your prompt",
156
+ show_label=False,
157
+ max_lines=1,
158
+ placeholder="Enter your prompt",
159
+ ).style(
160
+ border=(True, False, True, True),
161
+ rounded=(True, False, False, True),
162
+ container=False,
163
+ )
164
+ btn = gr.Button("Generate image").style(
165
+ margin=False,
166
+ rounded=(False, True, True, False),
167
+ )
168
+
169
+ gallery = gr.Gallery(
170
+ label="Generated images", show_label=False, elem_id="gallery"
171
+ ).style(grid=[2], height="auto")
172
+
173
+
174
+ with gr.Row(elem_id="advanced-options"):
175
+ samples = gr.Slider(label="Images", minimum=1, maximum=4, value=2, step=1)
176
+ steps = gr.Slider(label="Steps", minimum=1, maximum=50, value=25, step=1)
177
+ scale = gr.Slider(
178
+ label="Guidance Scale", minimum=0, maximum=50, value=7.5, step=0.1
179
+ )
180
+
181
+
182
+ ex = gr.Examples(examples=examples, fn=infer, inputs=[text, samples, scale], outputs=gallery, cache_examples=False)
183
+ ex.dataset.headers = [""]
184
+
185
+
186
+ text.submit(infer, inputs=[text, samples, steps, scale], outputs=gallery)
187
+ btn.click(infer, inputs=[text, samples, steps, scale], outputs=gallery)
188
+ gr.HTML(
189
+ """
190
+ <div class="footer">
191
+ <p> Gradio Demo by 🤗 Hugging Face and Lambda Labs
192
+ </p>
193
+ </div>
194
+ <div class="acknowledgments">
195
+ <p> Put in a text prompt and generate your own Pokémon character, no "prompt engineering" required!
196
+ <p>If you want to find out how we made this model read about it in <a href="https://lambdalabs.com/blog/how-to-fine-tune-stable-diffusion-how-we-made-the-text-to-pokemon-model-at-lambda/">this blog post</a>.
197
+ <p>And if you want to train your own Stable Diffusion variants, see our <a href="https://github.com/LambdaLabsML/examples/tree/main/stable-diffusion-finetuning">Examples Repo</a>!
198
+ </div>
199
+ """
200
+ )
201
+
202
+ block.launch()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ --extra-index-url https://download.pytorch.org/whl/cu113
2
+ torch
3
+ diffusers
4
+ transformers
5
+ scipy
6
+ ftfy
7
+ datasets