osanseviero HF staff commited on
Commit
bc34c30
1 Parent(s): 7031a30

Update pipeline.py

Browse files
Files changed (1) hide show
  1. pipeline.py +7 -3
pipeline.py CHANGED
@@ -1,7 +1,7 @@
1
  import torch
2
  import nltk
3
  import io
4
- import numpy as np
5
 
6
  from pytorch_pretrained_biggan import BigGAN, one_hot_from_names, truncated_noise_sample
7
 
@@ -15,7 +15,7 @@ class PreTrainedPipeline():
15
  self.truncation = 0.1
16
 
17
 
18
- def __call__(self, inputs: str) -> np.array:
19
  """
20
  Args:
21
  inputs (:obj:`str`):
@@ -35,4 +35,8 @@ class PreTrainedPipeline():
35
  with torch.no_grad():
36
  output = self.model(noise_vector, class_vector, self.truncation)
37
 
38
- return output[0].numpy()
 
 
 
 
 
1
  import torch
2
  import nltk
3
  import io
4
+ import base64
5
 
6
  from pytorch_pretrained_biggan import BigGAN, one_hot_from_names, truncated_noise_sample
7
 
 
15
  self.truncation = 0.1
16
 
17
 
18
+ def __call__(self, inputs: str) -> str:
19
  """
20
  Args:
21
  inputs (:obj:`str`):
 
35
  with torch.no_grad():
36
  output = self.model(noise_vector, class_vector, self.truncation)
37
 
38
+ img = transforms.ToPILImage()(output[0])
39
+ buf = io.BytesIO()
40
+ img.save(buf, format="JPEG")
41
+
42
+ return base64.encodebytes(buf.getvalue()).decode('utf-8')