Robert001 commited on
Commit
523db87
1 Parent(s): 4f3da39

safetensor update

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -34,6 +34,9 @@ import cvlib as cv
34
  from utils import create_model, load_state_dict
35
  from lib.ddim_hacked import DDIMSampler
36
 
 
 
 
37
  apply_uniformer = UniformerDetector()
38
  apply_midas = MidasDetector()
39
  apply_canny = CannyDetector()
@@ -74,17 +77,21 @@ def inpainting(img, res, rand_h, rand_h_1, rand_w, rand_w_1):
74
  result = model_inpainting(img, rand_h, rand_h_1, rand_w, rand_w_1)
75
  return result
76
 
77
-
78
  model = create_model('./models/cldm_v15_unicontrol.yaml').cpu()
79
- model_url = 'https://huggingface.co/Robert001/UniControl-Model/resolve/main/unicontrol_v1.1.ckpt'
 
 
80
  ckpts_path='./'
81
- model_path = os.path.join(ckpts_path, "unicontrol_v1.1.ckpt")
 
82
 
83
  if not os.path.exists(model_path):
84
  from basicsr.utils.download_util import load_file_from_url
85
  load_file_from_url(model_url, model_dir=ckpts_path)
86
 
87
- model.load_state_dict(load_state_dict(model_path, location='cuda'), strict=False)
 
 
88
  model = model.cuda()
89
  ddim_sampler = DDIMSampler(model)
90
 
@@ -943,7 +950,7 @@ with demo:
943
  Work done when Can Qin was an intern at Salesforce AI Research.
944
  </p>
945
  <p style="font-size: 0.9rem; margin: 0rem; line-height: 1.2em; margin-top:1em">
946
- <b> ONE model for AII the condition-to-image generation! </b>
947
  <b><a href="https://github.com/salesforce/UniControl">[Github]</a></b>
948
  <b><a href="https://canqin001.github.io/UniControl-Page/">[Website]</a></b>
949
  <b><a href="https://arxiv.org/abs/2305.11147">[arXiv]</a></b>
@@ -1316,6 +1323,8 @@ with demo:
1316
  ips = [input_image, prompt, a_prompt, n_prompt, num_samples, image_resolution, ddim_steps, guess_mode,
1317
  strength, scale, seed, eta, ksize, condition_mode]
1318
  run_button.click(fn=process_deblur, inputs=ips, outputs=[result_gallery])
 
 
1319
  gr.Markdown('''### Tips
1320
  - Please pay attention to <u> Condition Extraction </u> option.
1321
  - Positive prompts and negative prompts are very useful sometimes.
 
34
  from utils import create_model, load_state_dict
35
  from lib.ddim_hacked import DDIMSampler
36
 
37
+ from safetensors.torch import load_file as stload
38
+ from collections import OrderedDict
39
+
40
  apply_uniformer = UniformerDetector()
41
  apply_midas = MidasDetector()
42
  apply_canny = CannyDetector()
 
77
  result = model_inpainting(img, rand_h, rand_h_1, rand_w, rand_w_1)
78
  return result
79
 
 
80
  model = create_model('./models/cldm_v15_unicontrol.yaml').cpu()
81
+ # model_url = 'https://huggingface.co/Robert001/UniControl-Model/resolve/main/unicontrol_v1.1.ckpt'
82
+ model_url = 'https://huggingface.co/Robert001/UniControl-Model/resolve/main/unicontrol_v1.1.st'
83
+
84
  ckpts_path='./'
85
+ # model_path = os.path.join(ckpts_path, "unicontrol_v1.1.ckpt")
86
+ model_path = os.path.join(ckpts_path, "unicontrol_v1.1.st")
87
 
88
  if not os.path.exists(model_path):
89
  from basicsr.utils.download_util import load_file_from_url
90
  load_file_from_url(model_url, model_dir=ckpts_path)
91
 
92
+ model_dict = OrderedDict(stload(model_path, device='cpu'))
93
+ model.load_state_dict(model_dict, strict=False)
94
+ # model.load_state_dict(load_state_dict(model_path, location='cuda'), strict=False)
95
  model = model.cuda()
96
  ddim_sampler = DDIMSampler(model)
97
 
 
950
  Work done when Can Qin was an intern at Salesforce AI Research.
951
  </p>
952
  <p style="font-size: 0.9rem; margin: 0rem; line-height: 1.2em; margin-top:1em">
953
+ <b> ONE model for ALL the condition-to-image generation! </b>
954
  <b><a href="https://github.com/salesforce/UniControl">[Github]</a></b>
955
  <b><a href="https://canqin001.github.io/UniControl-Page/">[Website]</a></b>
956
  <b><a href="https://arxiv.org/abs/2305.11147">[arXiv]</a></b>
 
1323
  ips = [input_image, prompt, a_prompt, n_prompt, num_samples, image_resolution, ddim_steps, guess_mode,
1324
  strength, scale, seed, eta, ksize, condition_mode]
1325
  run_button.click(fn=process_deblur, inputs=ips, outputs=[result_gallery])
1326
+
1327
+
1328
  gr.Markdown('''### Tips
1329
  - Please pay attention to <u> Condition Extraction </u> option.
1330
  - Positive prompts and negative prompts are very useful sometimes.