Spaces:
Running
on
Zero
Running
on
Zero
zhiweili
commited on
Commit
•
5d1594c
1
Parent(s):
7892d1d
change to inpaint
Browse files- app.py +1 -1
- app_haircolor.py +9 -5
- app_haircolor_inpaint.py +12 -11
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
from
|
4 |
|
5 |
with gr.Blocks(css="style.css") as demo:
|
6 |
with gr.Tabs():
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
from app_haircolor_inpaint import create_demo as create_demo_haircolor
|
4 |
|
5 |
with gr.Blocks(css="style.css") as demo:
|
6 |
with gr.Tabs():
|
app_haircolor.py
CHANGED
@@ -38,10 +38,15 @@ pidinet_detector = pidinet_detector.to(DEVICE)
|
|
38 |
|
39 |
canndy_detector = CannyDetector()
|
40 |
|
|
|
|
|
|
|
|
|
|
|
41 |
adapters = MultiAdapter(
|
42 |
[
|
43 |
T2IAdapter.from_pretrained(
|
44 |
-
"TencentARC/
|
45 |
torch_dtype=torch.float16,
|
46 |
varient="fp16",
|
47 |
),
|
@@ -80,13 +85,12 @@ def image_to_image(
|
|
80 |
run_task_time = 0
|
81 |
time_cost_str = ''
|
82 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
83 |
-
|
84 |
-
|
85 |
canny_image = canndy_detector(input_image, int(generate_size*0.375), generate_size)
|
86 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
87 |
-
sketch_image = pidinet_detector(input_image, int(generate_size*0.5), generate_size)
|
88 |
|
89 |
-
cond_image = [
|
90 |
cond_scale = [lineart_scale, canny_scale]
|
91 |
|
92 |
generator = torch.Generator(device=DEVICE).manual_seed(seed)
|
|
|
38 |
|
39 |
canndy_detector = CannyDetector()
|
40 |
|
41 |
+
midas_detector = MidasDetector.from_pretrained(
|
42 |
+
"valhalla/t2iadapter-aux-models", filename="dpt_large_384.pt", model_type="dpt_large"
|
43 |
+
)
|
44 |
+
midas_detector = midas_detector.to(DEVICE)
|
45 |
+
|
46 |
adapters = MultiAdapter(
|
47 |
[
|
48 |
T2IAdapter.from_pretrained(
|
49 |
+
"TencentARC/t2i-adapter-lineart-sdxl-1.0",
|
50 |
torch_dtype=torch.float16,
|
51 |
varient="fp16",
|
52 |
),
|
|
|
85 |
run_task_time = 0
|
86 |
time_cost_str = ''
|
87 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
88 |
+
lineart_image = lineart_detector(input_image, int(generate_size*0.375), generate_size)
|
89 |
+
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
90 |
canny_image = canndy_detector(input_image, int(generate_size*0.375), generate_size)
|
91 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
|
|
92 |
|
93 |
+
cond_image = [lineart_image, canny_image]
|
94 |
cond_scale = [lineart_scale, canny_scale]
|
95 |
|
96 |
generator = torch.Generator(device=DEVICE).manual_seed(seed)
|
app_haircolor_inpaint.py
CHANGED
@@ -9,6 +9,7 @@ from segment_utils import(
|
|
9 |
restore_result,
|
10 |
)
|
11 |
from diffusers import (
|
|
|
12 |
DiffusionPipeline,
|
13 |
T2IAdapter,
|
14 |
MultiAdapter,
|
@@ -49,12 +50,12 @@ adapters = MultiAdapter(
|
|
49 |
)
|
50 |
adapters = adapters.to(torch.float16)
|
51 |
|
52 |
-
basepipeline =
|
53 |
BASE_MODEL,
|
54 |
torch_dtype=torch.float16,
|
55 |
use_safetensors=True,
|
56 |
-
adapter=adapters,
|
57 |
-
custom_pipeline="./pipelines/pipeline_sdxl_adapter_inpaint_custom.py",
|
58 |
)
|
59 |
|
60 |
basepipeline = basepipeline.to(DEVICE)
|
@@ -76,13 +77,13 @@ def image_to_image(
|
|
76 |
run_task_time = 0
|
77 |
time_cost_str = ''
|
78 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
79 |
-
lineart_image = lineart_detector(input_image, int(generate_size*0.375), generate_size)
|
80 |
-
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
81 |
-
canny_image = canndy_detector(input_image, int(generate_size*0.375), generate_size)
|
82 |
-
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
83 |
|
84 |
-
cond_image = [lineart_image, canny_image]
|
85 |
-
cond_scale = [lineart_scale, canny_scale]
|
86 |
|
87 |
generator = torch.Generator(device=DEVICE).manual_seed(seed)
|
88 |
generated_image = basepipeline(
|
@@ -95,8 +96,8 @@ def image_to_image(
|
|
95 |
width=generate_size,
|
96 |
guidance_scale=guidance_scale,
|
97 |
num_inference_steps=num_steps,
|
98 |
-
adapter_image=cond_image,
|
99 |
-
adapter_conditioning_scale=cond_scale,
|
100 |
).images[0]
|
101 |
|
102 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
|
|
9 |
restore_result,
|
10 |
)
|
11 |
from diffusers import (
|
12 |
+
StableDiffusionXLInpaintPipeline,
|
13 |
DiffusionPipeline,
|
14 |
T2IAdapter,
|
15 |
MultiAdapter,
|
|
|
50 |
)
|
51 |
adapters = adapters.to(torch.float16)
|
52 |
|
53 |
+
basepipeline = StableDiffusionXLInpaintPipeline.from_pretrained(
|
54 |
BASE_MODEL,
|
55 |
torch_dtype=torch.float16,
|
56 |
use_safetensors=True,
|
57 |
+
# adapter=adapters,
|
58 |
+
# custom_pipeline="./pipelines/pipeline_sdxl_adapter_inpaint_custom.py",
|
59 |
)
|
60 |
|
61 |
basepipeline = basepipeline.to(DEVICE)
|
|
|
77 |
run_task_time = 0
|
78 |
time_cost_str = ''
|
79 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
80 |
+
# lineart_image = lineart_detector(input_image, int(generate_size*0.375), generate_size)
|
81 |
+
# run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
82 |
+
# canny_image = canndy_detector(input_image, int(generate_size*0.375), generate_size)
|
83 |
+
# run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
84 |
|
85 |
+
# cond_image = [lineart_image, canny_image]
|
86 |
+
# cond_scale = [lineart_scale, canny_scale]
|
87 |
|
88 |
generator = torch.Generator(device=DEVICE).manual_seed(seed)
|
89 |
generated_image = basepipeline(
|
|
|
96 |
width=generate_size,
|
97 |
guidance_scale=guidance_scale,
|
98 |
num_inference_steps=num_steps,
|
99 |
+
# adapter_image=cond_image,
|
100 |
+
# adapter_conditioning_scale=cond_scale,
|
101 |
).images[0]
|
102 |
|
103 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|