Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,12 +11,12 @@ controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-scribble"
|
|
11 |
pipe = StableDiffusionControlNetPipeline.from_pretrained(
|
12 |
"runwayml/stable-diffusion-v1-5",
|
13 |
controlnet=controlnet,
|
14 |
-
torch_dtype=torch.float16
|
15 |
).to("cuda")
|
16 |
|
17 |
-
def generate_background(
|
18 |
# Удаление фона
|
19 |
-
image = Image.open(
|
20 |
output_image = remove(image)
|
21 |
|
22 |
# Преобразование изображения объекта в контурное изображение
|
@@ -29,7 +29,7 @@ def generate_background(image, prompt, negative_prompt):
|
|
29 |
result = pipe(
|
30 |
prompt=prompt,
|
31 |
negative_prompt=negative_prompt,
|
32 |
-
|
33 |
generator=generator,
|
34 |
num_inference_steps=50
|
35 |
)
|
@@ -48,11 +48,11 @@ def generate_background(image, prompt, negative_prompt):
|
|
48 |
iface = gr.Interface(
|
49 |
fn=generate_background,
|
50 |
inputs=[
|
51 |
-
gr.
|
52 |
-
gr.
|
53 |
-
gr.
|
54 |
],
|
55 |
-
outputs=gr.
|
56 |
)
|
57 |
|
58 |
# Запуск интерфейса
|
|
|
11 |
pipe = StableDiffusionControlNetPipeline.from_pretrained(
|
12 |
"runwayml/stable-diffusion-v1-5",
|
13 |
controlnet=controlnet,
|
14 |
+
# torch_dtype=torch.float16
|
15 |
).to("cuda")
|
16 |
|
17 |
+
def generate_background(image_path, prompt, negative_prompt):
|
18 |
# Удаление фона
|
19 |
+
image = Image.open(image_path).convert("RGBA")
|
20 |
output_image = remove(image)
|
21 |
|
22 |
# Преобразование изображения объекта в контурное изображение
|
|
|
29 |
result = pipe(
|
30 |
prompt=prompt,
|
31 |
negative_prompt=negative_prompt,
|
32 |
+
image=contour_image,
|
33 |
generator=generator,
|
34 |
num_inference_steps=50
|
35 |
)
|
|
|
48 |
iface = gr.Interface(
|
49 |
fn=generate_background,
|
50 |
inputs=[
|
51 |
+
gr.Image(type="filepath", label="Загрузите изображение"),
|
52 |
+
gr.Textbox(lines=2, placeholder="Введите позитивный промт", label="Позитивный промт"),
|
53 |
+
gr.Textbox(lines=2, placeholder="Введите негативный промт", label="Негативный промт")
|
54 |
],
|
55 |
+
outputs=gr.Image(type="pil", label="Результат")
|
56 |
)
|
57 |
|
58 |
# Запуск интерфейса
|