Spaces:
Runtime error
Runtime error
Commit
·
ac03725
1
Parent(s):
a99ac61
pinokio script + mac support
Browse files- app.py +8 -14
- icon.gif +0 -0
- install.js +28 -0
- pinokio.js +87 -0
- requirements.txt +2 -1
- reset.js +8 -0
- start.js +34 -0
- torch.js +74 -0
- update.js +8 -0
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
-
import spaces
|
3 |
import torch
|
4 |
from diffusers import AutoencoderKL, TCDScheduler
|
5 |
from diffusers.models.model_loading_utils import load_state_dict
|
@@ -8,7 +8,8 @@ from huggingface_hub import hf_hub_download
|
|
8 |
|
9 |
from controlnet_union import ControlNetModel_Union
|
10 |
from pipeline_fill_sd_xl import StableDiffusionXLFillPipeline
|
11 |
-
|
|
|
12 |
MODELS = {
|
13 |
"RealVisXL V5.0 Lightning": "SG161222/RealVisXL_V5.0_Lightning",
|
14 |
}
|
@@ -28,11 +29,11 @@ state_dict = load_state_dict(model_file)
|
|
28 |
model, _, _, _, _ = ControlNetModel_Union._load_pretrained_model(
|
29 |
controlnet_model, state_dict, model_file, "xinsir/controlnet-union-sdxl-1.0"
|
30 |
)
|
31 |
-
model.to(device=
|
32 |
|
33 |
vae = AutoencoderKL.from_pretrained(
|
34 |
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16
|
35 |
-
).to(
|
36 |
|
37 |
pipe = StableDiffusionXLFillPipeline.from_pretrained(
|
38 |
"SG161222/RealVisXL_V5.0_Lightning",
|
@@ -40,7 +41,7 @@ pipe = StableDiffusionXLFillPipeline.from_pretrained(
|
|
40 |
vae=vae,
|
41 |
controlnet=model,
|
42 |
variant="fp16",
|
43 |
-
).to(
|
44 |
|
45 |
pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
|
46 |
|
@@ -50,10 +51,10 @@ prompt = "high quality"
|
|
50 |
negative_prompt_embeds,
|
51 |
pooled_prompt_embeds,
|
52 |
negative_pooled_prompt_embeds,
|
53 |
-
) = pipe.encode_prompt(prompt,
|
54 |
|
55 |
|
56 |
-
|
57 |
def fill_image(image, model_selection):
|
58 |
source = image["background"]
|
59 |
mask = image["layers"][0]
|
@@ -89,14 +90,7 @@ css = """
|
|
89 |
"""
|
90 |
|
91 |
|
92 |
-
title = """<h1 align="center">Diffusers Image Fill</h1>
|
93 |
-
<div align="center">Draw the mask over the subject you want to erase or change.</div>
|
94 |
-
<div align="center">This space is a PoC made for the guide <a href='https://huggingface.co/blog/OzzyGT/diffusers-image-fill'>Diffusers Image Fill</a>.</div>
|
95 |
-
"""
|
96 |
-
|
97 |
with gr.Blocks(css=css) as demo:
|
98 |
-
gr.HTML(title)
|
99 |
-
|
100 |
run_button = gr.Button("Generate")
|
101 |
|
102 |
with gr.Row():
|
|
|
1 |
import gradio as gr
|
2 |
+
#import spaces
|
3 |
import torch
|
4 |
from diffusers import AutoencoderKL, TCDScheduler
|
5 |
from diffusers.models.model_loading_utils import load_state_dict
|
|
|
8 |
|
9 |
from controlnet_union import ControlNetModel_Union
|
10 |
from pipeline_fill_sd_xl import StableDiffusionXLFillPipeline
|
11 |
+
import devicetorch
|
12 |
+
DEVICE = devicetorch.get(torch)
|
13 |
MODELS = {
|
14 |
"RealVisXL V5.0 Lightning": "SG161222/RealVisXL_V5.0_Lightning",
|
15 |
}
|
|
|
29 |
model, _, _, _, _ = ControlNetModel_Union._load_pretrained_model(
|
30 |
controlnet_model, state_dict, model_file, "xinsir/controlnet-union-sdxl-1.0"
|
31 |
)
|
32 |
+
model.to(device=DEVICE, dtype=torch.float16)
|
33 |
|
34 |
vae = AutoencoderKL.from_pretrained(
|
35 |
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16
|
36 |
+
).to(DEVICE)
|
37 |
|
38 |
pipe = StableDiffusionXLFillPipeline.from_pretrained(
|
39 |
"SG161222/RealVisXL_V5.0_Lightning",
|
|
|
41 |
vae=vae,
|
42 |
controlnet=model,
|
43 |
variant="fp16",
|
44 |
+
).to(DEVICE)
|
45 |
|
46 |
pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
|
47 |
|
|
|
51 |
negative_prompt_embeds,
|
52 |
pooled_prompt_embeds,
|
53 |
negative_pooled_prompt_embeds,
|
54 |
+
) = pipe.encode_prompt(prompt, DEVICE, True)
|
55 |
|
56 |
|
57 |
+
#@spaces.GPU(duration=16)
|
58 |
def fill_image(image, model_selection):
|
59 |
source = image["background"]
|
60 |
mask = image["layers"][0]
|
|
|
90 |
"""
|
91 |
|
92 |
|
|
|
|
|
|
|
|
|
|
|
93 |
with gr.Blocks(css=css) as demo:
|
|
|
|
|
94 |
run_button = gr.Button("Generate")
|
95 |
|
96 |
with gr.Row():
|
icon.gif
ADDED
![]() |
install.js
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
module.exports = {
|
2 |
+
run: [
|
3 |
+
{
|
4 |
+
method: "script.start",
|
5 |
+
params: {
|
6 |
+
uri: "torch.js",
|
7 |
+
params: {
|
8 |
+
venv: "env", // Edit this to customize the venv folder path
|
9 |
+
// xformers: true // uncomment this line if your project requires xformers
|
10 |
+
}
|
11 |
+
}
|
12 |
+
},
|
13 |
+
// Edit this step with your custom install commands
|
14 |
+
{
|
15 |
+
method: "shell.run",
|
16 |
+
params: {
|
17 |
+
venv: "env", // Edit this to customize the venv folder path
|
18 |
+
message: "pip install -r requirements.txt"
|
19 |
+
}
|
20 |
+
},
|
21 |
+
{
|
22 |
+
method: "fs.link",
|
23 |
+
params: {
|
24 |
+
venv: "env"
|
25 |
+
}
|
26 |
+
}
|
27 |
+
]
|
28 |
+
}
|
pinokio.js
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const path = require('path')
|
2 |
+
module.exports = {
|
3 |
+
version: "2.0",
|
4 |
+
title: "diffusers-image-fill",
|
5 |
+
description: "Draw the mask over the subject you want to erase https://huggingface.co/spaces/OzzyGT/diffusers-image-fill",
|
6 |
+
icon: "icon.gif",
|
7 |
+
menu: async (kernel, info) => {
|
8 |
+
let installed = info.exists("env")
|
9 |
+
let running = {
|
10 |
+
install: info.running("install.js"),
|
11 |
+
start: info.running("start.js"),
|
12 |
+
update: info.running("update.js"),
|
13 |
+
reset: info.running("reset.js")
|
14 |
+
}
|
15 |
+
if (running.install) {
|
16 |
+
return [{
|
17 |
+
default: true,
|
18 |
+
icon: "fa-solid fa-plug",
|
19 |
+
text: "Installing",
|
20 |
+
href: "install.js",
|
21 |
+
}]
|
22 |
+
} else if (installed) {
|
23 |
+
if (running.start) {
|
24 |
+
let local = info.local("start.js")
|
25 |
+
if (local && local.url) {
|
26 |
+
return [{
|
27 |
+
default: true,
|
28 |
+
icon: "fa-solid fa-rocket",
|
29 |
+
text: "Open Web UI",
|
30 |
+
href: local.url,
|
31 |
+
}, {
|
32 |
+
icon: 'fa-solid fa-terminal',
|
33 |
+
text: "Terminal",
|
34 |
+
href: "start.js",
|
35 |
+
}]
|
36 |
+
} else {
|
37 |
+
return [{
|
38 |
+
default: true,
|
39 |
+
icon: 'fa-solid fa-terminal',
|
40 |
+
text: "Terminal",
|
41 |
+
href: "start.js",
|
42 |
+
}]
|
43 |
+
}
|
44 |
+
} else if (running.update) {
|
45 |
+
return [{
|
46 |
+
default: true,
|
47 |
+
icon: 'fa-solid fa-terminal',
|
48 |
+
text: "Updating",
|
49 |
+
href: "update.js",
|
50 |
+
}]
|
51 |
+
} else if (running.reset) {
|
52 |
+
return [{
|
53 |
+
default: true,
|
54 |
+
icon: 'fa-solid fa-terminal',
|
55 |
+
text: "Resetting",
|
56 |
+
href: "reset.js",
|
57 |
+
}]
|
58 |
+
} else {
|
59 |
+
return [{
|
60 |
+
default: true,
|
61 |
+
icon: "fa-solid fa-power-off",
|
62 |
+
text: "Start",
|
63 |
+
href: "start.js",
|
64 |
+
}, {
|
65 |
+
icon: "fa-solid fa-plug",
|
66 |
+
text: "Update",
|
67 |
+
href: "update.js",
|
68 |
+
}, {
|
69 |
+
icon: "fa-solid fa-plug",
|
70 |
+
text: "Install",
|
71 |
+
href: "install.js",
|
72 |
+
}, {
|
73 |
+
icon: "fa-regular fa-circle-xmark",
|
74 |
+
text: "Reset",
|
75 |
+
href: "reset.js",
|
76 |
+
}]
|
77 |
+
}
|
78 |
+
} else {
|
79 |
+
return [{
|
80 |
+
default: true,
|
81 |
+
icon: "fa-solid fa-plug",
|
82 |
+
text: "Install",
|
83 |
+
href: "install.js",
|
84 |
+
}]
|
85 |
+
}
|
86 |
+
}
|
87 |
+
}
|
requirements.txt
CHANGED
@@ -7,4 +7,5 @@ transformers
|
|
7 |
accelerate
|
8 |
diffusers
|
9 |
fastapi<0.113.0
|
10 |
-
opencv-python
|
|
|
|
7 |
accelerate
|
8 |
diffusers
|
9 |
fastapi<0.113.0
|
10 |
+
opencv-python
|
11 |
+
devicetorch
|
reset.js
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
module.exports = {
|
2 |
+
run: [{
|
3 |
+
method: "fs.rm",
|
4 |
+
params: {
|
5 |
+
path: "app"
|
6 |
+
}
|
7 |
+
}]
|
8 |
+
}
|
start.js
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
module.exports = {
|
2 |
+
daemon: true,
|
3 |
+
run: [
|
4 |
+
{
|
5 |
+
method: "shell.run",
|
6 |
+
params: {
|
7 |
+
venv: "env", // Edit this to customize the venv folder path
|
8 |
+
env: { }, // Edit this to customize environment variables (see documentation)
|
9 |
+
message: [
|
10 |
+
"python app.py", // Edit with your custom commands
|
11 |
+
],
|
12 |
+
on: [{
|
13 |
+
// The regular expression pattern to monitor.
|
14 |
+
// When this pattern occurs in the shell terminal, the shell will return,
|
15 |
+
// and the script will go onto the next step.
|
16 |
+
"event": "/http:\/\/[a-zA-Z0-9.:]+/",
|
17 |
+
|
18 |
+
// "done": true will move to the next step while keeping the shell alive.
|
19 |
+
// "kill": true will move to the next step after killing the shell.
|
20 |
+
"done": true
|
21 |
+
}]
|
22 |
+
}
|
23 |
+
},
|
24 |
+
{
|
25 |
+
// This step sets the local variable 'url'.
|
26 |
+
// This local variable will be used in pinokio.js to display the "Open WebUI" tab when the value is set.
|
27 |
+
method: "local.set",
|
28 |
+
params: {
|
29 |
+
// the input.event is the regular expression match object from the previous step
|
30 |
+
url: "{{input.event[0]}}"
|
31 |
+
}
|
32 |
+
}
|
33 |
+
]
|
34 |
+
}
|
torch.js
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
module.exports = {
|
2 |
+
run: [
|
3 |
+
// windows nvidia
|
4 |
+
{
|
5 |
+
"when": "{{platform === 'win32' && gpu === 'nvidia'}}",
|
6 |
+
"method": "shell.run",
|
7 |
+
"params": {
|
8 |
+
"venv": "{{args && args.venv ? args.venv : null}}",
|
9 |
+
"path": "{{args && args.path ? args.path : '.'}}",
|
10 |
+
"message": "pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 {{args && args.xformers ? 'xformers' : ''}} --index-url https://download.pytorch.org/whl/cu121"
|
11 |
+
}
|
12 |
+
},
|
13 |
+
// windows amd
|
14 |
+
{
|
15 |
+
"when": "{{platform === 'win32' && gpu === 'amd'}}",
|
16 |
+
"method": "shell.run",
|
17 |
+
"params": {
|
18 |
+
"venv": "{{args && args.venv ? args.venv : null}}",
|
19 |
+
"path": "{{args && args.path ? args.path : '.'}}",
|
20 |
+
"message": "pip install torch-directml torchaudio torchvision numpy==1.26.4"
|
21 |
+
}
|
22 |
+
},
|
23 |
+
// windows cpu
|
24 |
+
{
|
25 |
+
"when": "{{platform === 'win32' && (gpu !== 'nvidia' && gpu !== 'amd')}}",
|
26 |
+
"method": "shell.run",
|
27 |
+
"params": {
|
28 |
+
"venv": "{{args && args.venv ? args.venv : null}}",
|
29 |
+
"path": "{{args && args.path ? args.path : '.'}}",
|
30 |
+
"message": "pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1"
|
31 |
+
}
|
32 |
+
},
|
33 |
+
// mac
|
34 |
+
{
|
35 |
+
"when": "{{platform === 'darwin'}}",
|
36 |
+
"method": "shell.run",
|
37 |
+
"params": {
|
38 |
+
"venv": "{{args && args.venv ? args.venv : null}}",
|
39 |
+
"path": "{{args && args.path ? args.path : '.'}}",
|
40 |
+
"message": "pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1"
|
41 |
+
}
|
42 |
+
},
|
43 |
+
// linux nvidia
|
44 |
+
{
|
45 |
+
"when": "{{platform === 'linux' && gpu === 'nvidia'}}",
|
46 |
+
"method": "shell.run",
|
47 |
+
"params": {
|
48 |
+
"venv": "{{args && args.venv ? args.venv : null}}",
|
49 |
+
"path": "{{args && args.path ? args.path : '.'}}",
|
50 |
+
"message": "pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 {{args && args.xformers ? 'xformers' : ''}} --index-url https://download.pytorch.org/whl/cu121"
|
51 |
+
}
|
52 |
+
},
|
53 |
+
// linux rocm (amd)
|
54 |
+
{
|
55 |
+
"when": "{{platform === 'linux' && gpu === 'amd'}}",
|
56 |
+
"method": "shell.run",
|
57 |
+
"params": {
|
58 |
+
"venv": "{{args && args.venv ? args.venv : null}}",
|
59 |
+
"path": "{{args && args.path ? args.path : '.'}}",
|
60 |
+
"message": "pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --index-url https://download.pytorch.org/whl/rocm6.0"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
// linux cpu
|
64 |
+
{
|
65 |
+
"when": "{{platform === 'linux' && (gpu !== 'amd' && gpu !=='nvidia')}}",
|
66 |
+
"method": "shell.run",
|
67 |
+
"params": {
|
68 |
+
"venv": "{{args && args.venv ? args.venv : null}}",
|
69 |
+
"path": "{{args && args.path ? args.path : '.'}}",
|
70 |
+
"message": "pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 --index-url https://download.pytorch.org/whl/cpu"
|
71 |
+
}
|
72 |
+
}
|
73 |
+
]
|
74 |
+
}
|
update.js
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
module.exports = {
|
2 |
+
run: [{
|
3 |
+
method: "shell.run",
|
4 |
+
params: {
|
5 |
+
message: "git pull"
|
6 |
+
}
|
7 |
+
}]
|
8 |
+
}
|