Spaces:
Running
on
Zero
Running
on
Zero
BlockDetail
commited on
Commit
•
984cccb
1
Parent(s):
8794666
fix
Browse files- app.py +11 -7
- extension.py +0 -1
- requirements.txt +1 -1
app.py
CHANGED
@@ -10,8 +10,6 @@ negative_prompt = ""
|
|
10 |
device = torch.device('cuda')
|
11 |
pipe = None
|
12 |
|
13 |
-
print(gr.__version__)
|
14 |
-
|
15 |
@spaces.GPU
|
16 |
def load():
|
17 |
global pipe
|
@@ -36,7 +34,7 @@ with gr.Blocks() as demo:
|
|
36 |
with gr.Row():
|
37 |
gr.Textbox(label="Stroke Type", value="To sketch Blocking strokes, change brush color to green. To sketch Detail strokes, change brush color to black."),
|
38 |
dilation_strength = gr.Slider(7, 117, value=65, step=2, label="Dilation Strength"),
|
39 |
-
canvas = gr.Sketchpad(label="Sketch", sources=(),
|
40 |
prompt_box = gr.Textbox(label="Prompt")
|
41 |
with gr.Row():
|
42 |
btn = gr.Button("Generate")
|
@@ -80,14 +78,20 @@ with gr.Blocks() as demo:
|
|
80 |
if seed is None:
|
81 |
seed = np.random.randint(1000)
|
82 |
sketch_states[k][1] = seed
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
curr_sketch_image = Image.fromarray(curr_sketch[:, :, 0]).resize((512, 512))
|
85 |
|
86 |
-
curr_construction_image = Image.fromarray(255 - curr_sketch[:, :,
|
87 |
if np.sum(255 - np.array(curr_construction_image)) == 0:
|
88 |
curr_construction_image = None
|
89 |
|
90 |
-
curr_detail_image = Image.fromarray(curr_sketch[:, :,
|
91 |
|
92 |
if curr_construction_image is not None:
|
93 |
dilation_mask = Image.fromarray(255 - np.array(curr_construction_image)).filter(ImageFilter.MaxFilter(dilation))
|
@@ -111,7 +115,7 @@ with gr.Blocks() as demo:
|
|
111 |
background = i.copy()
|
112 |
background.putalpha(80)
|
113 |
background = Image.alpha_composite(Image.fromarray(255 * np.ones((512, 512)).astype(np.uint8)).convert("RGBA"), background)
|
114 |
-
overlay = Image.alpha_composite(background.resize((512, 512)), Image.fromarray(save_sketch).convert("RGBA"))
|
115 |
overlays.append(overlay.convert("RGB"))
|
116 |
|
117 |
new_overlays = []
|
@@ -119,7 +123,7 @@ with gr.Blocks() as demo:
|
|
119 |
background = i.copy()
|
120 |
background.putalpha(80)
|
121 |
background = Image.alpha_composite(Image.fromarray(255 * np.ones((512, 512)).astype(np.uint8)).convert("RGBA"), background)
|
122 |
-
overlay = Image.alpha_composite(background.resize((512, 512)), Image.fromarray(save_sketch).convert("RGBA"))
|
123 |
new_overlays.append(overlay.convert("RGB"))
|
124 |
|
125 |
global all_gens
|
|
|
10 |
device = torch.device('cuda')
|
11 |
pipe = None
|
12 |
|
|
|
|
|
13 |
@spaces.GPU
|
14 |
def load():
|
15 |
global pipe
|
|
|
34 |
with gr.Row():
|
35 |
gr.Textbox(label="Stroke Type", value="To sketch Blocking strokes, change brush color to green. To sketch Detail strokes, change brush color to black."),
|
36 |
dilation_strength = gr.Slider(7, 117, value=65, step=2, label="Dilation Strength"),
|
37 |
+
canvas = gr.Sketchpad(image_mode="RGBA", crop_size="1:1", label="Sketch", sources=(), brush = gr.Brush(colors=["#00FF00", "#000000"], default_size = 2, color_mode="fixed"))
|
38 |
prompt_box = gr.Textbox(label="Prompt")
|
39 |
with gr.Row():
|
40 |
btn = gr.Button("Generate")
|
|
|
78 |
if seed is None:
|
79 |
seed = np.random.randint(1000)
|
80 |
sketch_states[k][1] = seed
|
81 |
+
|
82 |
+
curr_sketch_image = Image.fromarray(curr_sketch["composite"])
|
83 |
+
curr_sketch = np.array(curr_sketch_image.resize((512, 512), resample=0))
|
84 |
+
curr_sketch[:, :, 0][curr_sketch[:, :, -1] == 0] = 255
|
85 |
+
curr_sketch[:, :, 2][curr_sketch[:, :, -1] == 0] = 255
|
86 |
+
curr_sketch[:, :, 1][curr_sketch[:, :, -1] == 0] = 255
|
87 |
|
88 |
curr_sketch_image = Image.fromarray(curr_sketch[:, :, 0]).resize((512, 512))
|
89 |
|
90 |
+
curr_construction_image = Image.fromarray(255 - curr_sketch[:, :, 1] + curr_sketch[:, :, 0])
|
91 |
if np.sum(255 - np.array(curr_construction_image)) == 0:
|
92 |
curr_construction_image = None
|
93 |
|
94 |
+
curr_detail_image = Image.fromarray(curr_sketch[:, :, 1]).resize((512, 512))
|
95 |
|
96 |
if curr_construction_image is not None:
|
97 |
dilation_mask = Image.fromarray(255 - np.array(curr_construction_image)).filter(ImageFilter.MaxFilter(dilation))
|
|
|
115 |
background = i.copy()
|
116 |
background.putalpha(80)
|
117 |
background = Image.alpha_composite(Image.fromarray(255 * np.ones((512, 512)).astype(np.uint8)).convert("RGBA"), background)
|
118 |
+
overlay = Image.alpha_composite(background.resize((512, 512)), Image.fromarray(save_sketch).resize((512, 512)).convert("RGBA"))
|
119 |
overlays.append(overlay.convert("RGB"))
|
120 |
|
121 |
new_overlays = []
|
|
|
123 |
background = i.copy()
|
124 |
background.putalpha(80)
|
125 |
background = Image.alpha_composite(Image.fromarray(255 * np.ones((512, 512)).astype(np.uint8)).convert("RGBA"), background)
|
126 |
+
overlay = Image.alpha_composite(background.resize((512, 512)), Image.fromarray(save_sketch).resize((512, 512)).convert("RGBA"))
|
127 |
new_overlays.append(overlay.convert("RGB"))
|
128 |
|
129 |
global all_gens
|
extension.py
CHANGED
@@ -8,7 +8,6 @@ import os
|
|
8 |
import inspect
|
9 |
import diffusers
|
10 |
path = inspect.getfile(diffusers)
|
11 |
-
print(path)
|
12 |
sys.path.append(os.path.join(path, "pipelines/controlnet"))
|
13 |
sys.path.append(path)
|
14 |
from diffusers.pipelines.controlnet.multicontrolnet import MultiControlNetModel
|
|
|
8 |
import inspect
|
9 |
import diffusers
|
10 |
path = inspect.getfile(diffusers)
|
|
|
11 |
sys.path.append(os.path.join(path, "pipelines/controlnet"))
|
12 |
sys.path.append(path)
|
13 |
from diffusers.pipelines.controlnet.multicontrolnet import MultiControlNetModel
|
requirements.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
diffusers==0.23.1
|
2 |
-
gradio==
|
3 |
pillow==9.4.0
|
4 |
torch==2.1.1
|
5 |
torchmetrics==0.6.0
|
|
|
1 |
diffusers==0.23.1
|
2 |
+
gradio==4.19.2
|
3 |
pillow==9.4.0
|
4 |
torch==2.1.1
|
5 |
torchmetrics==0.6.0
|