Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,8 @@
|
|
1 |
-
!pip install controlnet_aux
|
2 |
-
|
3 |
import gradio as gr
|
4 |
import numpy as np
|
5 |
import torch
|
6 |
from diffusers import StableDiffusionPipeline, ControlNetModel, StableDiffusionControlNetPipeline
|
7 |
from peft import PeftModel, LoraConfig
|
8 |
-
from controlnet_aux import OpenposeDetector
|
9 |
import os
|
10 |
|
11 |
MAX_SEED = np.iinfo(np.int32).max
|
@@ -15,9 +12,8 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
15 |
model_default = "stable-diffusion-v1-5/stable-diffusion-v1-5"
|
16 |
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
17 |
|
18 |
-
# Инициализация ControlNet
|
19 |
controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-openpose", torch_dtype=torch_dtype)
|
20 |
-
openpose = OpenposeDetector.from_pretrained("lllyasviel/ControlNet")
|
21 |
|
22 |
def get_lora_sd_pipeline(
|
23 |
lora_dir='./lora_man_animestyle',
|
@@ -81,18 +77,17 @@ def infer(
|
|
81 |
lora_scale=0.5,
|
82 |
use_control_net=False, # Параметр для включения ControlNet
|
83 |
control_strength=0.5, # Сила влияния ControlNet
|
84 |
-
control_image=None, # Контрольное изображение
|
85 |
progress=gr.Progress(track_tqdm=True)
|
86 |
):
|
87 |
generator = torch.Generator(device).manual_seed(seed)
|
88 |
|
89 |
if use_control_net and control_image is not None:
|
90 |
# Используем ControlNet
|
91 |
-
pose_image = openpose(control_image)
|
92 |
image = pipe_controlnet(
|
93 |
prompt=prompt,
|
94 |
negative_prompt=negative_prompt,
|
95 |
-
image=
|
96 |
width=width,
|
97 |
height=height,
|
98 |
num_inference_steps=num_inference_steps,
|
@@ -251,7 +246,7 @@ with gr.Blocks(css=css) as demo:
|
|
251 |
value="pose_estimation",
|
252 |
)
|
253 |
|
254 |
-
control_image = gr.Image(label="Upload Control Image")
|
255 |
|
256 |
use_control_net.change(
|
257 |
fn=lambda x: gr.Row.update(visible=x),
|
@@ -287,3 +282,4 @@ with gr.Blocks(css=css) as demo:
|
|
287 |
|
288 |
if __name__ == "__main__":
|
289 |
demo.launch()
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import torch
|
4 |
from diffusers import StableDiffusionPipeline, ControlNetModel, StableDiffusionControlNetPipeline
|
5 |
from peft import PeftModel, LoraConfig
|
|
|
6 |
import os
|
7 |
|
8 |
MAX_SEED = np.iinfo(np.int32).max
|
|
|
12 |
model_default = "stable-diffusion-v1-5/stable-diffusion-v1-5"
|
13 |
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
14 |
|
15 |
+
# Инициализация ControlNet
|
16 |
controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-openpose", torch_dtype=torch_dtype)
|
|
|
17 |
|
18 |
def get_lora_sd_pipeline(
|
19 |
lora_dir='./lora_man_animestyle',
|
|
|
77 |
lora_scale=0.5,
|
78 |
use_control_net=False, # Параметр для включения ControlNet
|
79 |
control_strength=0.5, # Сила влияния ControlNet
|
80 |
+
control_image=None, # Контрольное изображение (карта позы)
|
81 |
progress=gr.Progress(track_tqdm=True)
|
82 |
):
|
83 |
generator = torch.Generator(device).manual_seed(seed)
|
84 |
|
85 |
if use_control_net and control_image is not None:
|
86 |
# Используем ControlNet
|
|
|
87 |
image = pipe_controlnet(
|
88 |
prompt=prompt,
|
89 |
negative_prompt=negative_prompt,
|
90 |
+
image=control_image, # Используем загруженное изображение как карту позы
|
91 |
width=width,
|
92 |
height=height,
|
93 |
num_inference_steps=num_inference_steps,
|
|
|
246 |
value="pose_estimation",
|
247 |
)
|
248 |
|
249 |
+
control_image = gr.Image(label="Upload Control Image (Pose Map)")
|
250 |
|
251 |
use_control_net.change(
|
252 |
fn=lambda x: gr.Row.update(visible=x),
|
|
|
282 |
|
283 |
if __name__ == "__main__":
|
284 |
demo.launch()
|
285 |
+
|