File size: 854 Bytes
29a5ed9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
-- Mix Clip encoded texts - Yownas

prompt = 'dog'
prompt2 = 'cat'

-- We need to clear the gallery before we start.
-- ui.gallery.getgif() will fail later if there is anthing
-- but images in the gellery.
ui.gallery.clear()

p = sd.getp()
p.seed = 4

-- Get encoded text from both prompts
p1 = sd.textencode(prompt)
p2 = sd.textencode(prompt2)

for weight = 0, 1, 0.1
do
  -- Mix p1 and p2
  c = torch.lerp(p1, p2, weight)
  -- sd.sample wants a conditional and unconditional object
  -- but will also take a string as argument and change it
  -- to what it needs, so we don't have to bother creating
  -- a proper unconditional value for it here.
  latent = sd.sample(p, c, '')
  ui.gallery.addc(sd.toimage(sd.vae(latent)), weight)
end

-- Create a gif from the images in the gallery
gif = ui.gallery.getgif(200)
ui.gallery.addc(gif, 'Dog to cat gif')