eolecvk commited on
Commit
eda7afa
·
1 Parent(s): 56b4d7a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -38
app.py CHANGED
@@ -2,39 +2,17 @@ from contextlib import nullcontext
2
  import gradio as gr
3
  import torch
4
  from torch import autocast
5
- from diffusers import StableDiffusionPipeline, StableDiffusionOnnxPipeline
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
- # Sometimes the nsfw checker is confused by the Pokémon images, you can disable
13
- try:
14
- if device == "cuda":
15
- pipe = StableDiffusionPipeline.from_pretrained("lambdalabs/sd-naruto-diffusers", torch_dtype=dtype)
16
-
17
- else:
18
- pipe = StableDiffusionOnnxPipeline.from_pretrained(
19
- "lambdalabs/sd-naruto-diffusers",
20
- revision="onnx",
21
- provider="CPUExecutionProvider"
22
- )
23
-
24
- # onnx model revision not available
25
- except:
26
- pipe = StableDiffusionPipeline.from_pretrained("lambdalabs/sd-naruto-diffusers", torch_dtype=dtype)
27
-
28
  pipe = pipe.to(device)
29
 
30
- # Sometimes the nsfw checker is confused by the Naruto images, you can disable
31
- # it at your own risk here
32
- disable_safety = True
33
-
34
- if disable_safety:
35
- def null_safety(images, **kwargs):
36
- return images, False
37
- pipe.safety_checker = null_safety
38
 
39
 
40
  def infer(prompt, n_samples, steps, scale):
@@ -129,19 +107,19 @@ block = gr.Blocks(css=css)
129
 
130
  examples = [
131
  [
132
- 'Bill Gates with a hoodie',
133
  2,
134
  7.5,
135
  ],
136
  [
137
- 'Jon Snow ninja portrait',
138
  2,
139
  7.5,
140
  ],
141
  [
142
- 'Leo Messi in the style of Naruto',
143
  2,
144
- 7.5
145
  ],
146
  ]
147
 
@@ -153,13 +131,9 @@ with block:
153
  <img class="logo" src="https://lambdalabs.com/hubfs/logos/lambda-logo.svg" alt="Lambda Logo"
154
  style="margin: auto; max-width: 7rem;">
155
  <h1 style="font-weight: 900; font-size: 3rem;">
156
- Naruto text to image
157
  </h1>
158
  </div>
159
- <p style="margin-bottom: 10px; font-size: 94%">
160
- Generate new Naruto anime character from a text description,
161
- <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>.
162
- </p>
163
  </div>
164
  """
165
  )
@@ -188,7 +162,7 @@ with block:
188
 
189
  with gr.Row(elem_id="advanced-options"):
190
  samples = gr.Slider(label="Images", minimum=1, maximum=4, value=2, step=1)
191
- steps = gr.Slider(label="Steps", minimum=5, maximum=50, value=45, step=5)
192
  scale = gr.Slider(
193
  label="Guidance Scale", minimum=0, maximum=50, value=7.5, step=0.1
194
  )
@@ -207,10 +181,8 @@ with block:
207
  </p>
208
  </div>
209
  <div class="acknowledgments">
210
- <p> Put in a text prompt and generate your own Naruto anime character!
211
- <p> Here are some <a href="https://huggingface.co/lambdalabs/sd-naruto-diffusers">examples</a> of generated images.
212
  <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>.
213
- <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>!
214
  <p>Trained by Eole Cervenka at <a href="https://lambdalabs.com/">Lambda Labs</a>.</p>
215
  </div>
216
  """
 
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
+ model_id = 'eolecvk/dreambooth-avatar'
13
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=dtype)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  pipe = pipe.to(device)
15
 
 
 
 
 
 
 
 
 
16
 
17
 
18
  def infer(prompt, n_samples, steps, scale):
 
107
 
108
  examples = [
109
  [
110
+ 'Jeff Bezos, avatarart style person',
111
  2,
112
  7.5,
113
  ],
114
  [
115
+ 'Elon Musk, avatarart style person',
116
  2,
117
  7.5,
118
  ],
119
  [
120
+ 'Bill Gates, avatarart style person',
121
  2,
122
+ 7,
123
  ],
124
  ]
125
 
 
131
  <img class="logo" src="https://lambdalabs.com/hubfs/logos/lambda-logo.svg" alt="Lambda Logo"
132
  style="margin: auto; max-width: 7rem;">
133
  <h1 style="font-weight: 900; font-size: 3rem;">
134
+ Avatar text to image
135
  </h1>
136
  </div>
 
 
 
 
137
  </div>
138
  """
139
  )
 
162
 
163
  with gr.Row(elem_id="advanced-options"):
164
  samples = gr.Slider(label="Images", minimum=1, maximum=4, value=2, step=1)
165
+ steps = gr.Slider(label="Steps", minimum=5, maximum=50, value=50, step=5)
166
  scale = gr.Slider(
167
  label="Guidance Scale", minimum=0, maximum=50, value=7.5, step=0.1
168
  )
 
181
  </p>
182
  </div>
183
  <div class="acknowledgments">
184
+ <p> Put in a text prompt and generate your own Avatar art style image!
 
185
  <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>.
 
186
  <p>Trained by Eole Cervenka at <a href="https://lambdalabs.com/">Lambda Labs</a>.</p>
187
  </div>
188
  """