Freiburg-AI-Research commited on
Commit
89fe730
Β·
1 Parent(s): bce7d81

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -119,7 +119,14 @@ def get_images(batch: th.Tensor):
119
  reshaped = scaled.permute(2, 0, 3, 1).reshape([batch.shape[2], -1, 3])
120
  return Image.fromarray(reshaped.numpy())
121
 
122
-
 
 
 
 
 
 
 
123
  # Create a classifier-free guidance sampling function
124
  guidance_scale = 8.0
125
 
@@ -133,8 +140,7 @@ def model_fn(x_t, ts, **kwargs):
133
  eps = th.cat([half_eps, half_eps], dim=0)
134
  return th.cat([eps, rest], dim=1)
135
 
136
- def to_base64(pil_image, size=(64, 64)):
137
- pil_image.thumbnail(size, Image.ANTIALIAS)
138
  buffered = BytesIO()
139
  pil_image.save(buffered, format="JPEG")
140
  return base64.b64encode(buffered.getvalue())
 
119
  reshaped = scaled.permute(2, 0, 3, 1).reshape([batch.shape[2], -1, 3])
120
  return Image.fromarray(reshaped.numpy())
121
 
122
+ def get_images(batch: th.Tensor):
123
+ """ Display a batch of images inline. """
124
+ scaled = ((batch + 1)*127.5).round().clamp(0,255).to(th.uint8).cpu()
125
+ reshaped = scaled.permute(2, 0, 3, 1).reshape([batch.shape[2], -1, 3])
126
+ image = Image.fromarray(reshaped.numpy())
127
+ image = image.resize((image.width // 2, image.height // 2), Image.ANTIALIAS)
128
+ return image
129
+
130
  # Create a classifier-free guidance sampling function
131
  guidance_scale = 8.0
132
 
 
140
  eps = th.cat([half_eps, half_eps], dim=0)
141
  return th.cat([eps, rest], dim=1)
142
 
143
+ def to_base64(pil_image):
 
144
  buffered = BytesIO()
145
  pil_image.save(buffered, format="JPEG")
146
  return base64.b64encode(buffered.getvalue())