vittore commited on
Commit
4e78ee8
1 Parent(s): 1a99702
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +17 -8
README.md CHANGED
@@ -9,7 +9,7 @@ pinned: false
9
  license: openrail
10
  hf_oauth: true
11
  disable_embedding: true
12
- short_description: Generate stunning high quality illusion artwork
13
  ---
14
 
15
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
9
  license: openrail
10
  hf_oauth: true
11
  disable_embedding: true
12
+ short_description: Generate high quality illusion artwork from a pattern and a prompt
13
  ---
14
 
15
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py CHANGED
@@ -35,10 +35,15 @@ controlnet = ControlNetModel.from_pretrained("monster-labs/control_v1p_sd15_qrco
35
  SAFETY_CHECKER_ENABLED = os.environ.get("SAFETY_CHECKER", "0") == "1"
36
  safety_checker = None
37
  feature_extractor = None
 
 
 
 
38
  if SAFETY_CHECKER_ENABLED:
39
- safety_checker = StableDiffusionSafetyChecker.from_pretrained("CompVis/stable-diffusion-safety-checker").to("cuda")
40
  feature_extractor = CLIPImageProcessor.from_pretrained("openai/clip-vit-base-patch32")
41
 
 
42
  main_pipe = StableDiffusionControlNetPipeline.from_pretrained(
43
  BASE_MODEL,
44
  controlnet=controlnet,
@@ -46,7 +51,7 @@ main_pipe = StableDiffusionControlNetPipeline.from_pretrained(
46
  safety_checker=safety_checker,
47
  feature_extractor=feature_extractor,
48
  torch_dtype=torch.float16,
49
- ).to("cuda")
50
 
51
  # Function to check NSFW images
52
  #def check_nsfw_images(images: list[Image.Image]) -> tuple[list[Image.Image], list[bool]]:
@@ -164,7 +169,7 @@ def inference(
164
 
165
  main_pipe.scheduler = SAMPLER_MAP[sampler](main_pipe.scheduler.config)
166
  my_seed = random.randint(0, 2**32 - 1) if seed == -1 else seed
167
- generator = torch.Generator(device="cuda").manual_seed(my_seed)
168
 
169
  out = main_pipe(
170
  prompt=prompt,
@@ -221,11 +226,15 @@ with gr.Blocks() as app:
221
  gr.Markdown(
222
  '''
223
  <div style="text-align: center;">
224
- <h1>Illusion Diffusion HQ 🌀</h1>
225
  <p style="font-size:16px;">Generate stunning high quality illusion artwork with Stable Diffusion</p>
226
  <p>Illusion Diffusion is back up with a safety checker! Because I have been asked, if you would like to support me, consider using <a href="https://deforum.studio">deforum.studio</a></p>
227
- <p>A space by AP <a href="https://twitter.com/angrypenguinPNG">Follow me on Twitter</a> with big contributions from <a href="https://twitter.com/multimodalart">multimodalart</a></p>
228
- <p>This project works by using <a href="https://huggingface.co/monster-labs/control_v1p_sd15_qrcode_monster">Monster Labs QR Control Net</a>. Given a prompt and your pattern, we use a QR code conditioned controlnet to create a stunning illusion! Credit to: <a href="https://twitter.com/MrUgleh">MrUgleh</a> for discovering the workflow :)</p>
 
 
 
 
229
  </div>
230
  '''
231
  )
@@ -235,7 +244,7 @@ with gr.Blocks() as app:
235
  state_img_output = gr.State()
236
  with gr.Row():
237
  with gr.Column():
238
- control_image = gr.Image(label="Input Illusion", type="pil", elem_id="control_image")
239
  controlnet_conditioning_scale = gr.Slider(minimum=0.0, maximum=5.0, step=0.01, value=0.8, label="Illusion strength", elem_id="illusion_strength", info="ControlNet conditioning scale")
240
  gr.Examples(examples=["checkers.png", "checkers_mid.jpg", "pattern.png", "ultra_checkers.png", "spiral.jpeg", "funky.jpeg" ], inputs=control_image)
241
  prompt = gr.Textbox(label="Prompt", elem_id="prompt", info="Type what you want to generate", placeholder="Medieval village scene with busy streets and castle in the distance")
@@ -250,7 +259,7 @@ with gr.Blocks() as app:
250
  used_seed = gr.Number(label="Last seed used",interactive=False)
251
  run_btn = gr.Button("Run")
252
  with gr.Column():
253
- result_image = gr.Image(label="Illusion Diffusion Output", interactive=False, elem_id="output")
254
  with gr.Group(elem_id="share-btn-container", visible=False) as share_group:
255
  community_icon = gr.HTML(community_icon_html)
256
  loading_icon = gr.HTML(loading_icon_html)
 
35
  SAFETY_CHECKER_ENABLED = os.environ.get("SAFETY_CHECKER", "0") == "1"
36
  safety_checker = None
37
  feature_extractor = None
38
+ device='cuda'
39
+ device='cpu'
40
+
41
+
42
  if SAFETY_CHECKER_ENABLED:
43
+ safety_checker = StableDiffusionSafetyChecker.from_pretrained("CompVis/stable-diffusion-safety-checker").to(device)
44
  feature_extractor = CLIPImageProcessor.from_pretrained("openai/clip-vit-base-patch32")
45
 
46
+
47
  main_pipe = StableDiffusionControlNetPipeline.from_pretrained(
48
  BASE_MODEL,
49
  controlnet=controlnet,
 
51
  safety_checker=safety_checker,
52
  feature_extractor=feature_extractor,
53
  torch_dtype=torch.float16,
54
+ ).to(device)
55
 
56
  # Function to check NSFW images
57
  #def check_nsfw_images(images: list[Image.Image]) -> tuple[list[Image.Image], list[bool]]:
 
169
 
170
  main_pipe.scheduler = SAMPLER_MAP[sampler](main_pipe.scheduler.config)
171
  my_seed = random.randint(0, 2**32 - 1) if seed == -1 else seed
172
+ generator = torch.Generator(device=device).manual_seed(my_seed)
173
 
174
  out = main_pipe(
175
  prompt=prompt,
 
226
  gr.Markdown(
227
  '''
228
  <div style="text-align: center;">
229
+ <h1>pattern + prompt = image</h1>
230
  <p style="font-size:16px;">Generate stunning high quality illusion artwork with Stable Diffusion</p>
231
  <p>Illusion Diffusion is back up with a safety checker! Because I have been asked, if you would like to support me, consider using <a href="https://deforum.studio">deforum.studio</a></p>
232
+ <p>With big contributions from
233
+ <ul>
234
+ <li><a href="https://twitter.com/multimodalart">multimodalart</a></li>
235
+ <li><a href="https://huggingface.co/monster-labs/control_v1p_sd15_qrcode_monster">Monster Labs QR Control Net</a></li>
236
+ <li><a href="https://twitter.com/MrUgleh">MrUgleh</a>/li>
237
+ </ul>
238
  </div>
239
  '''
240
  )
 
244
  state_img_output = gr.State()
245
  with gr.Row():
246
  with gr.Column():
247
+ control_image = gr.Image(label="Input pattern", type="pil", elem_id="control_image")
248
  controlnet_conditioning_scale = gr.Slider(minimum=0.0, maximum=5.0, step=0.01, value=0.8, label="Illusion strength", elem_id="illusion_strength", info="ControlNet conditioning scale")
249
  gr.Examples(examples=["checkers.png", "checkers_mid.jpg", "pattern.png", "ultra_checkers.png", "spiral.jpeg", "funky.jpeg" ], inputs=control_image)
250
  prompt = gr.Textbox(label="Prompt", elem_id="prompt", info="Type what you want to generate", placeholder="Medieval village scene with busy streets and castle in the distance")
 
259
  used_seed = gr.Number(label="Last seed used",interactive=False)
260
  run_btn = gr.Button("Run")
261
  with gr.Column():
262
+ result_image = gr.Image(label="Output", interactive=False, elem_id="output")
263
  with gr.Group(elem_id="share-btn-container", visible=False) as share_group:
264
  community_icon = gr.HTML(community_icon_html)
265
  loading_icon = gr.HTML(loading_icon_html)