Spaces:
Runtime error
Runtime error
TakahashiShotaro
commited on
Commit
•
311538b
1
Parent(s):
2074ae5
Update pipelines.py
Browse files- pipelines.py +30 -25
pipelines.py
CHANGED
@@ -16,46 +16,52 @@ from diffusers import ControlNetModel, UniPCMultistepScheduler
|
|
16 |
from diffusers import StableDiffusionInpaintPipeline
|
17 |
|
18 |
from config import WIDTH, HEIGHT
|
19 |
-
from stable_diffusion_controlnet_inpaint_img2img import
|
|
|
|
|
20 |
from helpers import flush
|
21 |
|
22 |
LOGGING = logging.getLogger(__name__)
|
23 |
|
|
|
24 |
class ControlNetPipeline:
|
25 |
def __init__(self):
|
26 |
self.in_use = False
|
27 |
self.controlnet = ControlNetModel.from_pretrained(
|
28 |
-
|
|
|
29 |
|
30 |
self.pipe = StableDiffusionControlNetInpaintImg2ImgPipeline.from_pretrained(
|
31 |
"runwayml/stable-diffusion-inpainting",
|
32 |
controlnet=self.controlnet,
|
33 |
safety_checker=None,
|
34 |
-
torch_dtype=torch.float16
|
35 |
)
|
36 |
|
37 |
-
self.pipe.scheduler = UniPCMultistepScheduler.from_config(
|
|
|
|
|
38 |
self.pipe.enable_xformers_memory_efficient_attention()
|
39 |
self.pipe = self.pipe.to("cuda")
|
40 |
-
|
41 |
self.waiting_queue = []
|
42 |
self.count = 0
|
43 |
-
|
44 |
@property
|
45 |
def queue_size(self):
|
46 |
return len(self.waiting_queue)
|
47 |
-
|
48 |
def __call__(self, **kwargs):
|
49 |
self.count += 1
|
50 |
number = self.count
|
51 |
|
52 |
self.waiting_queue.append(number)
|
53 |
-
|
54 |
# wait until the next number in the queue is the current number
|
55 |
-
while self.waiting_queue[0] != number:
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
|
60 |
# it's your turn, so remove the number from the queue
|
61 |
# and call the function
|
@@ -64,7 +70,8 @@ class ControlNetPipeline:
|
|
64 |
self.waiting_queue.pop(0)
|
65 |
flush()
|
66 |
return results
|
67 |
-
|
|
|
68 |
class SDPipeline:
|
69 |
def __init__(self):
|
70 |
self.pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
@@ -75,25 +82,25 @@ class SDPipeline:
|
|
75 |
|
76 |
self.pipe.enable_xformers_memory_efficient_attention()
|
77 |
self.pipe = self.pipe.to("cuda")
|
78 |
-
|
79 |
self.waiting_queue = []
|
80 |
self.count = 0
|
81 |
-
|
82 |
@property
|
83 |
def queue_size(self):
|
84 |
return len(self.waiting_queue)
|
85 |
-
|
86 |
def __call__(self, **kwargs):
|
87 |
self.count += 1
|
88 |
number = self.count
|
89 |
|
90 |
self.waiting_queue.append(number)
|
91 |
-
|
92 |
# wait until the next number in the queue is the current number
|
93 |
-
while self.waiting_queue[0] != number:
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
|
98 |
# it's your turn, so remove the number from the queue
|
99 |
# and call the function
|
@@ -104,8 +111,7 @@ class SDPipeline:
|
|
104 |
return results
|
105 |
|
106 |
|
107 |
-
|
108 |
-
@st.experimental_singleton(max_entries=5)
|
109 |
def get_controlnet():
|
110 |
"""Method to load the controlnet model
|
111 |
Returns:
|
@@ -115,8 +121,7 @@ def get_controlnet():
|
|
115 |
return pipe
|
116 |
|
117 |
|
118 |
-
|
119 |
-
@st.experimental_singleton(max_entries=5)
|
120 |
def get_inpainting_pipeline():
|
121 |
"""Method to load the inpainting pipeline
|
122 |
Returns:
|
|
|
16 |
from diffusers import StableDiffusionInpaintPipeline
|
17 |
|
18 |
from config import WIDTH, HEIGHT
|
19 |
+
from stable_diffusion_controlnet_inpaint_img2img import (
|
20 |
+
StableDiffusionControlNetInpaintImg2ImgPipeline,
|
21 |
+
)
|
22 |
from helpers import flush
|
23 |
|
24 |
LOGGING = logging.getLogger(__name__)
|
25 |
|
26 |
+
|
27 |
class ControlNetPipeline:
|
28 |
def __init__(self):
|
29 |
self.in_use = False
|
30 |
self.controlnet = ControlNetModel.from_pretrained(
|
31 |
+
"BertChristiaens/controlnet-seg-room", torch_dtype=torch.float16
|
32 |
+
)
|
33 |
|
34 |
self.pipe = StableDiffusionControlNetInpaintImg2ImgPipeline.from_pretrained(
|
35 |
"runwayml/stable-diffusion-inpainting",
|
36 |
controlnet=self.controlnet,
|
37 |
safety_checker=None,
|
38 |
+
torch_dtype=torch.float16,
|
39 |
)
|
40 |
|
41 |
+
self.pipe.scheduler = UniPCMultistepScheduler.from_config(
|
42 |
+
self.pipe.scheduler.config
|
43 |
+
)
|
44 |
self.pipe.enable_xformers_memory_efficient_attention()
|
45 |
self.pipe = self.pipe.to("cuda")
|
46 |
+
|
47 |
self.waiting_queue = []
|
48 |
self.count = 0
|
49 |
+
|
50 |
@property
|
51 |
def queue_size(self):
|
52 |
return len(self.waiting_queue)
|
53 |
+
|
54 |
def __call__(self, **kwargs):
|
55 |
self.count += 1
|
56 |
number = self.count
|
57 |
|
58 |
self.waiting_queue.append(number)
|
59 |
+
|
60 |
# wait until the next number in the queue is the current number
|
61 |
+
# while self.waiting_queue[0] != number:
|
62 |
+
# print(f"Wait for your turn {number} in queue {self.waiting_queue}")
|
63 |
+
# time.sleep(0.5)
|
64 |
+
# pass
|
65 |
|
66 |
# it's your turn, so remove the number from the queue
|
67 |
# and call the function
|
|
|
70 |
self.waiting_queue.pop(0)
|
71 |
flush()
|
72 |
return results
|
73 |
+
|
74 |
+
|
75 |
class SDPipeline:
|
76 |
def __init__(self):
|
77 |
self.pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
|
|
82 |
|
83 |
self.pipe.enable_xformers_memory_efficient_attention()
|
84 |
self.pipe = self.pipe.to("cuda")
|
85 |
+
|
86 |
self.waiting_queue = []
|
87 |
self.count = 0
|
88 |
+
|
89 |
@property
|
90 |
def queue_size(self):
|
91 |
return len(self.waiting_queue)
|
92 |
+
|
93 |
def __call__(self, **kwargs):
|
94 |
self.count += 1
|
95 |
number = self.count
|
96 |
|
97 |
self.waiting_queue.append(number)
|
98 |
+
|
99 |
# wait until the next number in the queue is the current number
|
100 |
+
# while self.waiting_queue[0] != number:
|
101 |
+
# print(f"Wait for your turn {number} in queue {self.waiting_queue}")
|
102 |
+
# time.sleep(0.5)
|
103 |
+
# pass
|
104 |
|
105 |
# it's your turn, so remove the number from the queue
|
106 |
# and call the function
|
|
|
111 |
return results
|
112 |
|
113 |
|
114 |
+
@st.experimental_singleton(max_entries=5,show_spinner=False)
|
|
|
115 |
def get_controlnet():
|
116 |
"""Method to load the controlnet model
|
117 |
Returns:
|
|
|
121 |
return pipe
|
122 |
|
123 |
|
124 |
+
@st.experimental_singleton(max_entries=5,show_spinner=False)
|
|
|
125 |
def get_inpainting_pipeline():
|
126 |
"""Method to load the inpainting pipeline
|
127 |
Returns:
|