Vivien Chappelier commited on
Commit
3f4f0fe
β€’
1 Parent(s): ff54256

add external script to run demo on a folder

Browse files
Files changed (1) hide show
  1. gen_sdxl_turbo.py +26 -0
gen_sdxl_turbo.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from app import BZHStableSignatureDemo
2
+ import sys
3
+ from pathlib import Path
4
+
5
+ def generate_all(captions, outdir='out'):
6
+ backend = BZHStableSignatureDemo()
7
+ decoders = list(backend.decoders.keys())
8
+ outdir = Path(outdir)
9
+ outdir.mkdir(parents=True, exist_ok=True)
10
+
11
+ for decoder in decoders:
12
+ # TODO: optimize by patching only once..
13
+ # TEMP
14
+ if decoder != 'medium':
15
+ continue
16
+ outdirdec = Path(outdir) / Path(decoder)
17
+ outdirdec.mkdir(parents=True, exist_ok = True)
18
+ for i, prompt in enumerate(captions):
19
+ img = backend.generate(decoder, 0, prompt)
20
+ img.save(outdirdec / Path('%04d.png' % i), format='PNG')
21
+
22
+ if __name__ == '__main__':
23
+ infile = sys.argv[1]
24
+ outdir = sys.argv[2]
25
+ with open(infile) as f:
26
+ generate_all([line.strip() for line in f.readlines()], outdir=outdir)