ironjr commited on
Commit
b91f391
1 Parent(s): 51d0e59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -18,10 +18,6 @@
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
  # SOFTWARE.
20
 
21
- import sys
22
-
23
- sys.path.append('../../src')
24
-
25
  import argparse
26
  import random
27
  import time
@@ -29,6 +25,7 @@ import json
29
  import os
30
  import glob
31
  import pathlib
 
32
  from functools import partial
33
  from pprint import pprint
34
  from multiprocessing.connection import Client, Listener
@@ -95,6 +92,19 @@ opt = parser.parse_args()
95
 
96
  device = f'cuda:{opt.device}' if opt.device >= 0 else 'cpu'
97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
  if opt.model is None:
100
  # opt.model = 'cagliostrolab/animagine-xl-3.1'
@@ -105,6 +115,11 @@ else:
105
  if opt.model.endswith('.safetensors'):
106
  opt.model = os.path.abspath(os.path.join('checkpoints', opt.model))
107
 
 
 
 
 
 
108
  # model = StreamMultiDiffusionSDXL(
109
  model = StreamMultiDiffusion(
110
  device,
@@ -160,7 +175,6 @@ opt.prep_time = -3
160
 
161
  ### Load examples
162
 
163
- root = pathlib.Path(__file__).parent
164
  example_root = os.path.join(root, 'examples')
165
  example_images = glob.glob(os.path.join(example_root, '*.png'))
166
  example_images = [Image.open(i) for i in example_images]
 
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
  # SOFTWARE.
20
 
 
 
 
 
21
  import argparse
22
  import random
23
  import time
 
25
  import os
26
  import glob
27
  import pathlib
28
+ import requests
29
  from functools import partial
30
  from pprint import pprint
31
  from multiprocessing.connection import Client, Listener
 
92
 
93
  device = f'cuda:{opt.device}' if opt.device >= 0 else 'cpu'
94
 
95
+ def download_file(url, root):
96
+ local_filename = url.split('/')[-1]
97
+ # NOTE the stream=True parameter below
98
+ with requests.get(url, stream=True) as r:
99
+ r.raise_for_status()
100
+ with open(os.path.join(root, local_filename), 'wb') as f:
101
+ for chunk in r.iter_content(chunk_size=8192):
102
+ # If you have chunk encoded response uncomment if
103
+ # and set chunk_size parameter to None.
104
+ #if chunk:
105
+ f.write(chunk)
106
+ return local_filename
107
+
108
 
109
  if opt.model is None:
110
  # opt.model = 'cagliostrolab/animagine-xl-3.1'
 
115
  if opt.model.endswith('.safetensors'):
116
  opt.model = os.path.abspath(os.path.join('checkpoints', opt.model))
117
 
118
+ root = pathlib.Path(__file__).parent
119
+ checkpoint_root = os.path.join(root, 'checkpoints')
120
+ opt.model = download_file(opt.model, checkpoint_root)
121
+ print(opt.model, checkpoint_root)
122
+
123
  # model = StreamMultiDiffusionSDXL(
124
  model = StreamMultiDiffusion(
125
  device,
 
175
 
176
  ### Load examples
177
 
 
178
  example_root = os.path.join(root, 'examples')
179
  example_images = glob.glob(os.path.join(example_root, '*.png'))
180
  example_images = [Image.open(i) for i in example_images]