Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
|
|
3 |
from PIL import Image
|
4 |
import cv2
|
5 |
import qrcode
|
6 |
-
import os, random
|
7 |
import numpy as np
|
8 |
from transformers import pipeline
|
9 |
import PIL.Image
|
@@ -82,10 +82,11 @@ models =[
|
|
82 |
|
83 |
controlnet = accelerator.prepare(ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-canny", torch_dtype=torch.float32))
|
84 |
def plex(qr_code_value, text, neg_text, modil, one, two, three):
|
85 |
-
|
86 |
apol=[]
|
87 |
modal=""+modil+""
|
88 |
pipe = accelerator.prepare(StableDiffusionControlNetPipeline.from_pretrained(modal, controlnet=controlnet, torch_dtype=torch.float32, use_safetensors=False, safety_checker=None))
|
|
|
89 |
pipe.scheduler = accelerator.prepare(DPMSolverMultistepScheduler.from_config(pipe.scheduler.config))
|
90 |
pipe = pipe.to("cpu")
|
91 |
negative_prompt = "monochrome, lowres, bad anatomy, worst quality, low quality"
|
@@ -103,6 +104,7 @@ def plex(qr_code_value, text, neg_text, modil, one, two, three):
|
|
103 |
cannyimage = np.concatenate([cannyimage, cannyimage, cannyimage], axis=2)
|
104 |
cannyimage = Image.fromarray(cannyimage)
|
105 |
images = [cannyimage]
|
|
|
106 |
|
107 |
image = pipe(
|
108 |
[prompt]*2,
|
@@ -113,7 +115,7 @@ def plex(qr_code_value, text, neg_text, modil, one, two, three):
|
|
113 |
negative_prompt=[neg_prompt]*2,
|
114 |
controlnet_conditioning_scale=three,
|
115 |
)
|
116 |
-
for i, imge in enumerate(
|
117 |
apol.append(imge)
|
118 |
apol.append(original)
|
119 |
apol.append(cannyimage)
|
|
|
3 |
from PIL import Image
|
4 |
import cv2
|
5 |
import qrcode
|
6 |
+
import os, random, gc
|
7 |
import numpy as np
|
8 |
from transformers import pipeline
|
9 |
import PIL.Image
|
|
|
82 |
|
83 |
controlnet = accelerator.prepare(ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-canny", torch_dtype=torch.float32))
|
84 |
def plex(qr_code_value, text, neg_text, modil, one, two, three):
|
85 |
+
gc.collect()
|
86 |
apol=[]
|
87 |
modal=""+modil+""
|
88 |
pipe = accelerator.prepare(StableDiffusionControlNetPipeline.from_pretrained(modal, controlnet=controlnet, torch_dtype=torch.float32, use_safetensors=False, safety_checker=None))
|
89 |
+
pipe.unet.to(memory_format=torch.channels_last)
|
90 |
pipe.scheduler = accelerator.prepare(DPMSolverMultistepScheduler.from_config(pipe.scheduler.config))
|
91 |
pipe = pipe.to("cpu")
|
92 |
negative_prompt = "monochrome, lowres, bad anatomy, worst quality, low quality"
|
|
|
104 |
cannyimage = np.concatenate([cannyimage, cannyimage, cannyimage], axis=2)
|
105 |
cannyimage = Image.fromarray(cannyimage)
|
106 |
images = [cannyimage]
|
107 |
+
generator = torch.Generator(device="cpu").manual_seed(random.randint(1, 4836923))
|
108 |
|
109 |
image = pipe(
|
110 |
[prompt]*2,
|
|
|
115 |
negative_prompt=[neg_prompt]*2,
|
116 |
controlnet_conditioning_scale=three,
|
117 |
)
|
118 |
+
for i, imge in enumerate(image["images"]):
|
119 |
apol.append(imge)
|
120 |
apol.append(original)
|
121 |
apol.append(cannyimage)
|