Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,8 @@ import uuid
|
|
9 |
import torch
|
10 |
from PIL import Image
|
11 |
|
|
|
|
|
12 |
demo_path = Path(__file__).resolve().parent
|
13 |
root_path = demo_path
|
14 |
sys.path.append(str(root_path))
|
@@ -70,12 +72,20 @@ inpainting_models = OrderedDict([
|
|
70 |
("Stable-Inpainting 2.0", 'sd2_inp'),
|
71 |
("Stable-Inpainting 1.5", 'sd15_inp')
|
72 |
])
|
73 |
-
sr_model =
|
74 |
-
sam_predictor =
|
75 |
|
76 |
inp_model_name = list(inpainting_models.keys())[0]
|
77 |
-
inp_model =
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
|
81 |
def set_model_from_name(new_inp_model_name):
|
@@ -84,7 +94,7 @@ def set_model_from_name(new_inp_model_name):
|
|
84 |
if new_inp_model_name != inp_model_name:
|
85 |
print (f"Activating Inpaintng Model: {new_inp_model_name}")
|
86 |
inp_model = models.load_inpainting_model(
|
87 |
-
inpainting_models[new_inp_model_name], device='cuda
|
88 |
inp_model_name = new_inp_model_name
|
89 |
|
90 |
|
@@ -132,6 +142,7 @@ def recover_user_session(session_id):
|
|
132 |
return hr_image, hr_mask, gallery, prompt
|
133 |
|
134 |
|
|
|
135 |
def inpainting_run(model_name, use_rasg, use_painta, prompt, imageMask,
|
136 |
hr_image, seed, eta, negative_prompt, positive_prompt, ddim_steps,
|
137 |
guidance_scale=7.5, batch_size=1, session_id=''
|
@@ -193,6 +204,7 @@ def inpainting_run(model_name, use_rasg, use_painta, prompt, imageMask,
|
|
193 |
return blended_images, session_id
|
194 |
|
195 |
|
|
|
196 |
def upscale_run(
|
197 |
ddim_steps, seed, use_sam_mask, session_id, img_index,
|
198 |
negative_prompt='', positive_prompt='high resolution professional photo'
|
@@ -375,5 +387,6 @@ with gr.Blocks(css=demo_path / 'style.css') as demo:
|
|
375 |
_js="function(a, b, c, d, e){ return [a, b, c, d, selected_gallery_index()] }",
|
376 |
)
|
377 |
|
|
|
378 |
demo.queue(max_size=20)
|
379 |
demo.launch(share=True, allowed_paths=[str(TMP_DIR)])
|
|
|
9 |
import torch
|
10 |
from PIL import Image
|
11 |
|
12 |
+
import spaces
|
13 |
+
|
14 |
demo_path = Path(__file__).resolve().parent
|
15 |
root_path = demo_path
|
16 |
sys.path.append(str(root_path))
|
|
|
72 |
("Stable-Inpainting 2.0", 'sd2_inp'),
|
73 |
("Stable-Inpainting 1.5", 'sd15_inp')
|
74 |
])
|
75 |
+
sr_model = None
|
76 |
+
sam_predictor = None
|
77 |
|
78 |
inp_model_name = list(inpainting_models.keys())[0]
|
79 |
+
inp_model = None
|
80 |
+
|
81 |
+
|
82 |
+
@spaces.GPU(duration=120)
|
83 |
+
def load_models():
|
84 |
+
global sr_model, sam_predictor, inp_model
|
85 |
+
sr_model = models.sd2_sr.load_model(device='cuda')
|
86 |
+
sam_predictor = models.sam.load_model(device='cuda')
|
87 |
+
inp_model = models.load_inpainting_model(
|
88 |
+
inpainting_models[inp_model_name], device='cuda', cache=True)
|
89 |
|
90 |
|
91 |
def set_model_from_name(new_inp_model_name):
|
|
|
94 |
if new_inp_model_name != inp_model_name:
|
95 |
print (f"Activating Inpaintng Model: {new_inp_model_name}")
|
96 |
inp_model = models.load_inpainting_model(
|
97 |
+
inpainting_models[new_inp_model_name], device='cuda', cache=True)
|
98 |
inp_model_name = new_inp_model_name
|
99 |
|
100 |
|
|
|
142 |
return hr_image, hr_mask, gallery, prompt
|
143 |
|
144 |
|
145 |
+
@spaces.GPU(duration=120)
|
146 |
def inpainting_run(model_name, use_rasg, use_painta, prompt, imageMask,
|
147 |
hr_image, seed, eta, negative_prompt, positive_prompt, ddim_steps,
|
148 |
guidance_scale=7.5, batch_size=1, session_id=''
|
|
|
204 |
return blended_images, session_id
|
205 |
|
206 |
|
207 |
+
@spaces.GPU(duration=120)
|
208 |
def upscale_run(
|
209 |
ddim_steps, seed, use_sam_mask, session_id, img_index,
|
210 |
negative_prompt='', positive_prompt='high resolution professional photo'
|
|
|
387 |
_js="function(a, b, c, d, e){ return [a, b, c, d, selected_gallery_index()] }",
|
388 |
)
|
389 |
|
390 |
+
load_models()
|
391 |
demo.queue(max_size=20)
|
392 |
demo.launch(share=True, allowed_paths=[str(TMP_DIR)])
|