Muhammadreza commited on
Commit
0b0bc86
1 Parent(s): 71cc78c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -4
app.py CHANGED
@@ -6,8 +6,13 @@ import numpy as np
6
  from diffusers import DiffusionPipeline, DPMSolverSinglestepScheduler, ControlNetModel, StableDiffusionXLControlNetPipeline, AutoencoderKL
7
  import requests
8
  import cv2
 
 
 
9
 
10
- pipe = DiffusionPipeline.from_pretrained("mann-e/Mann-E_Dreams", torch_dtype=torch.float16).to("cuda")
 
 
11
  pipe.scheduler = DPMSolverSinglestepScheduler.from_config(pipe.scheduler.config, use_karras_sigmas=True)
12
 
13
  #pipe.enable_xformers_memory_efficient_attention()
@@ -16,17 +21,37 @@ pipe.enable_vae_slicing()
16
  torch.cuda.empty_cache()
17
 
18
  @spaces.GPU
19
- def genie (prompt, negative_prompt, width, height, steps, seed):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  generator = np.random.seed(0) if seed == 0 else torch.manual_seed(seed)
21
- int_image = pipe(prompt=prompt, negative_prompt=negative_prompt, width=width, height=height, generator=generator, num_inference_steps=steps, guidance_scale=3.0).images[0]
22
  return int_image
23
 
24
- gr.Interface(fn=genie, inputs=[gr.Textbox(label='What you want the AI to generate. 75 Token Limit.'),
 
25
  gr.Textbox(label='What you DO NOT want the AI to generate. 75 Token Limit.'),
26
  gr.Slider(576, maximum=1280, value=768, step=16, label='Width (can go up to 1280, but for square images maximum is 1024x1024)'),
27
  gr.Slider(576, maximum=1280, value=768, step=16, label='Height (can go up to 1280, but for square images maximum is 1024x1024)'),
28
  gr.Slider(1, maximum=8, value=6, step=1, label='Number of Iterations'),
29
  gr.Slider(minimum=0, step=1, maximum=999999999999999999, randomize=True, label="Seed"),
 
30
  ],
31
  outputs='image',
32
  title="Mann-E Dreams",
 
6
  from diffusers import DiffusionPipeline, DPMSolverSinglestepScheduler, ControlNetModel, StableDiffusionXLControlNetPipeline, AutoencoderKL
7
  import requests
8
  import cv2
9
+ from uuid import uuid4
10
+ import numpy as np
11
+ from PIL import Image
12
 
13
+ controlnet = ControlNetModel.from_pretrained("diffusers/controlnet-canny-sdxl-1.0", torch_dtype=torch.float16).to("cuda")
14
+
15
+ pipe = StableDiffusionXLControlNetPipeline.from_pretrained("mann-e/Mann-E_Dreams", controlnet=controlnet, torch_dtype=torch.float16).to("cuda")
16
  pipe.scheduler = DPMSolverSinglestepScheduler.from_config(pipe.scheduler.config, use_karras_sigmas=True)
17
 
18
  #pipe.enable_xformers_memory_efficient_attention()
 
21
  torch.cuda.empty_cache()
22
 
23
  @spaces.GPU
24
+ def genie (input_image, prompt, negative_prompt, width, height, steps, seed):
25
+ #processing the input image
26
+ res = requests.get(input_image)
27
+ image_name = f'tmp_{uuid4()}.png'
28
+
29
+ if res.ok:
30
+ with open(image_name, 'wb') as f:
31
+ f.write(res.content)
32
+
33
+ # Canny Edge Detection
34
+ image = cv2.imread(image_name)
35
+ image = np.array(image)
36
+ image = cv2.Canny(image, 100, 200)
37
+ image = image[:, :, None]
38
+ image = np.concatenate([image, image, image], axis=2)
39
+ #cv2.imwrite('canny.png', image)
40
+ image = Image.fromarray(image)
41
+
42
+ #generating a new image
43
  generator = np.random.seed(0) if seed == 0 else torch.manual_seed(seed)
44
+ int_image = pipe(prompt=prompt, negative_prompt=negative_prompt, width=width, height=height, generator=generator, num_inference_steps=steps, guidance_scale=3.0, image=image, controlnet_conditioning_scale=conditioning_scale).images[0]
45
  return int_image
46
 
47
+ gr.Interface(fn=genie, inputs=[gr.Textbox(label='Base Image URL'),
48
+ gr.Textbox(label='What you want the AI to generate. 75 Token Limit.'),
49
  gr.Textbox(label='What you DO NOT want the AI to generate. 75 Token Limit.'),
50
  gr.Slider(576, maximum=1280, value=768, step=16, label='Width (can go up to 1280, but for square images maximum is 1024x1024)'),
51
  gr.Slider(576, maximum=1280, value=768, step=16, label='Height (can go up to 1280, but for square images maximum is 1024x1024)'),
52
  gr.Slider(1, maximum=8, value=6, step=1, label='Number of Iterations'),
53
  gr.Slider(minimum=0, step=1, maximum=999999999999999999, randomize=True, label="Seed"),
54
+ gr.Slider(minimum=0, step=0.05, maximum=1, label="Conditioning Scale"),
55
  ],
56
  outputs='image',
57
  title="Mann-E Dreams",