qbration21 commited on
Commit
1e0dc47
·
1 Parent(s): 5768419

파라미터 추가

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +51 -50
  3. requirements.txt +3 -5
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .venv
app.py CHANGED
@@ -8,7 +8,7 @@ import requests
8
  import io
9
  import os
10
  from PIL import Image
11
- import spaces
12
 
13
  from diffusers import (
14
  StableDiffusionPipeline,
@@ -29,14 +29,14 @@ qrcode_generator = qrcode.QRCode(
29
  )
30
 
31
  controlnet = ControlNetModel.from_pretrained(
32
- "DionTimmer/controlnet_qrcode-control_v1p_sd15", torch_dtype=torch.float16
33
  ) #.to("cuda")
34
 
35
  pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
36
  "runwayml/stable-diffusion-v1-5",
37
  controlnet=controlnet,
38
  safety_checker=None,
39
- torch_dtype=torch.float16,
40
  ) #.to("cuda")
41
  # pipe.enable_xformers_memory_efficient_attention()
42
 
@@ -62,7 +62,7 @@ SAMPLER_MAP = {
62
  "DEIS": lambda config: DEISMultistepScheduler.from_config(config),
63
  }
64
 
65
- @spaces.GPU()
66
  def inference(
67
  qr_code_content: str,
68
  prompt: str,
@@ -72,8 +72,9 @@ def inference(
72
  strength: float = 0.8,
73
  seed: int = -1,
74
  init_image: Image.Image | None = None,
75
- custom_image: Image.Image | None = None,
76
- use_qr_code_as_init_image = True,
 
77
  sampler = "DPM++ Karras SDE",
78
  ):
79
  if prompt is None or prompt == "":
@@ -99,9 +100,9 @@ def inference(
99
 
100
  qrcode_image = qr.make_image(fill_color="black", back_color="white")
101
  qrcode_image = resize_for_condition_image(qrcode_image, 768)
102
- if custom_image is None:
103
  print("Using QR Code Image")
104
- custom_image = qrcode_image
105
 
106
  out = pipe(
107
  prompt=prompt,
@@ -114,7 +115,9 @@ def inference(
114
  controlnet_conditioning_scale=float(controlnet_conditioning_scale), # type: ignore
115
  generator=generator,
116
  strength=float(strength),
117
- num_inference_steps=40,
 
 
118
  )
119
  return out.images[0] # type: ignore
120
 
@@ -143,11 +146,7 @@ model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
143
  info="QR Code Content or URL",
144
  value="",
145
  )
146
- with gr.Accordion(label="init Image (Optional)"):#, open=False):
147
- custom_image = gr.Image(
148
- label="Init Code Image Leave blank to automatically generate QR code",
149
- type="pil",
150
- )
151
 
152
  prompt = gr.Textbox(
153
  label="Prompt",
@@ -157,9 +156,8 @@ model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
157
  label="Negative Prompt",
158
  value="ugly, disfigured, low quality, blurry, nsfw",
159
  )
160
- use_qr_code_as_init_image = gr.Checkbox(label="Use QR code as init image", value=True, interactive=False, info="Whether init image should be QR code. Unclick to pass init image or generate init image with Stable Diffusion 2.1")
161
 
162
- with gr.Accordion(label="Init Images (Optional)", open=False, visible=False) as init_image_acc:
163
  init_image = gr.Image(label="Init Image (Optional). Leave blank to generate image with SD 2.1", type="pil")
164
 
165
 
@@ -174,12 +172,12 @@ model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
174
  value=1.1,
175
  label="Controlnet Conditioning Scale",
176
  )
177
- steps = gr.Slider(
178
  minimum=20,
179
  maximum=50,
180
  step=1,
181
  value=20,
182
- label="Steps",
183
  )
184
  strength = gr.Slider(
185
  minimum=0.0, maximum=1.0, step=0.01, value=0.9, label="Strength"
@@ -229,8 +227,9 @@ model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
229
  strength,
230
  seed,
231
  init_image,
232
- custom_image,
233
- use_qr_code_as_init_image,
 
234
  sampler,
235
  ],
236
  outputs=[result_image],
@@ -248,36 +247,37 @@ model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
248
  0.9,
249
  5392011833,
250
  None,
251
- None,
252
- True,
253
- "DPM++ Karras SDE",
254
- ],
255
- [
256
- "https://huggingface.co/",
257
- "Bright sunshine coming through the cracks of a wet, cave wall of big rocks",
258
- "ugly, disfigured, low quality, blurry, nsfw",
259
- 7.5,
260
- 1.11,
261
- 0.9,
262
- 2523992465,
263
- None,
264
- None,
265
- True,
266
- "DPM++ Karras SDE",
267
- ],
268
- [
269
- "https://huggingface.co/",
270
- "Sky view of highly aesthetic, ancient greek thermal baths in beautiful nature",
271
- "ugly, disfigured, low quality, blurry, nsfw",
272
- 7.5,
273
- 1.5,
274
- 0.9,
275
- 2523992465,
276
- None,
277
- None,
278
- True,
279
  "DPM++ Karras SDE",
280
  ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281
  ],
282
  fn=inference,
283
  inputs=[
@@ -289,8 +289,9 @@ model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
289
  strength,
290
  seed,
291
  init_image,
292
- custom_image,
293
- use_qr_code_as_init_image,
 
294
  sampler,
295
  ],
296
  outputs=[result_image],
 
8
  import io
9
  import os
10
  from PIL import Image
11
+ # import spaces
12
 
13
  from diffusers import (
14
  StableDiffusionPipeline,
 
29
  )
30
 
31
  controlnet = ControlNetModel.from_pretrained(
32
+ "DionTimmer/controlnet_qrcode-control_v1p_sd15", torch_dtype=torch.float32
33
  ) #.to("cuda")
34
 
35
  pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
36
  "runwayml/stable-diffusion-v1-5",
37
  controlnet=controlnet,
38
  safety_checker=None,
39
+ torch_dtype=torch.float32,
40
  ) #.to("cuda")
41
  # pipe.enable_xformers_memory_efficient_attention()
42
 
 
62
  "DEIS": lambda config: DEISMultistepScheduler.from_config(config),
63
  }
64
 
65
+ # @spaces.GPU()
66
  def inference(
67
  qr_code_content: str,
68
  prompt: str,
 
72
  strength: float = 0.8,
73
  seed: int = -1,
74
  init_image: Image.Image | None = None,
75
+ control_guidance_start: float = 0,
76
+ control_guidance_end: float = 1,
77
+ num_inference_steps: int = 20,
78
  sampler = "DPM++ Karras SDE",
79
  ):
80
  if prompt is None or prompt == "":
 
100
 
101
  qrcode_image = qr.make_image(fill_color="black", back_color="white")
102
  qrcode_image = resize_for_condition_image(qrcode_image, 768)
103
+ if init_image is None:
104
  print("Using QR Code Image")
105
+ init_image = qrcode_image
106
 
107
  out = pipe(
108
  prompt=prompt,
 
115
  controlnet_conditioning_scale=float(controlnet_conditioning_scale), # type: ignore
116
  generator=generator,
117
  strength=float(strength),
118
+ num_inference_steps=num_inference_steps,
119
+ control_guidance_start=control_guidance_start,
120
+ control_guidance_end=control_guidance_end,
121
  )
122
  return out.images[0] # type: ignore
123
 
 
146
  info="QR Code Content or URL",
147
  value="",
148
  )
149
+
 
 
 
 
150
 
151
  prompt = gr.Textbox(
152
  label="Prompt",
 
156
  label="Negative Prompt",
157
  value="ugly, disfigured, low quality, blurry, nsfw",
158
  )
 
159
 
160
+ with gr.Accordion(label="Init Images (Optional)", open=True):
161
  init_image = gr.Image(label="Init Image (Optional). Leave blank to generate image with SD 2.1", type="pil")
162
 
163
 
 
172
  value=1.1,
173
  label="Controlnet Conditioning Scale",
174
  )
175
+ num_inference_steps = gr.Slider(
176
  minimum=20,
177
  maximum=50,
178
  step=1,
179
  value=20,
180
+ label="num_inference_steps",
181
  )
182
  strength = gr.Slider(
183
  minimum=0.0, maximum=1.0, step=0.01, value=0.9, label="Strength"
 
227
  strength,
228
  seed,
229
  init_image,
230
+ control_guidance_start,
231
+ control_guidance_end,
232
+ num_inference_steps,
233
  sampler,
234
  ],
235
  outputs=[result_image],
 
247
  0.9,
248
  5392011833,
249
  None,
250
+ 0,
251
+ 1,
252
+ 20,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  "DPM++ Karras SDE",
254
  ],
255
+ # [
256
+ # "https://huggingface.co/",
257
+ # "Bright sunshine coming through the cracks of a wet, cave wall of big rocks",
258
+ # "ugly, disfigured, low quality, blurry, nsfw",
259
+ # 7.5,
260
+ # 1.11,
261
+ # 0.9,
262
+ # 2523992465,
263
+ # None,
264
+ # None,
265
+ # True,
266
+ # "DPM++ Karras SDE",
267
+ # ],
268
+ # [
269
+ # "https://huggingface.co/",
270
+ # "Sky view of highly aesthetic, ancient greek thermal baths in beautiful nature",
271
+ # "ugly, disfigured, low quality, blurry, nsfw",
272
+ # 7.5,
273
+ # 1.5,
274
+ # 0.9,
275
+ # 2523992465,
276
+ # None,
277
+ # None,
278
+ # True,
279
+ # "DPM++ Karras SDE",
280
+ # ],
281
  ],
282
  fn=inference,
283
  inputs=[
 
289
  strength,
290
  seed,
291
  init_image,
292
+ control_guidance_start,
293
+ control_guidance_end,
294
+ num_inference_steps,
295
  sampler,
296
  ],
297
  outputs=[result_image],
requirements.txt CHANGED
@@ -1,9 +1,7 @@
1
- diffusers
2
- transformers
3
  accelerate
4
- torch
5
- xformers
6
- gradio
7
  Pillow
8
  qrcode
9
  gradio==4.8.0
 
1
+ diffusers==0.25.0
2
+ transformers==4.27.2
3
  accelerate
4
+ torch==2.0.1
 
 
5
  Pillow
6
  qrcode
7
  gradio==4.8.0