hr16 commited on
Commit
3b78729
·
1 Parent(s): e7f7175
Files changed (1) hide show
  1. app.py +12 -0
app.py CHANGED
@@ -9,6 +9,8 @@ import stylegan2
9
  from stylegan2 import utils
10
  from huggingface_hub import hf_hub_download
11
 
 
 
12
  def generate_images(G, args):
13
  latent_size, label_size = G.latent_size, G.label_size
14
  device = torch.device(args.gpu[0] if args.gpu else 'cpu')
@@ -77,6 +79,16 @@ def generate_images(G, args):
77
  def inference(seed):
78
  G = stylegan2.models.load(hf_hub_download("hr16/Gwern-TWDNEv3-pytorch_ckpt", "Gs.pth", use_auth_token=os.environ['MODEL_READING_TOKEN']))
79
  G.eval()
 
 
 
 
 
 
 
 
 
 
80
 
81
  title = "TWDNEv3 CPU Generator"
82
  description = "Gradio Demo for TWDNEv3 CPU Generator (stylegan2_pytorch port). To use it, simply put your random seed."
 
9
  from stylegan2 import utils
10
  from huggingface_hub import hf_hub_download
11
 
12
+ from types import SimpleNamespace
13
+
14
  def generate_images(G, args):
15
  latent_size, label_size = G.latent_size, G.label_size
16
  device = torch.device(args.gpu[0] if args.gpu else 'cpu')
 
79
  def inference(seed):
80
  G = stylegan2.models.load(hf_hub_download("hr16/Gwern-TWDNEv3-pytorch_ckpt", "Gs.pth", use_auth_token=os.environ['MODEL_READING_TOKEN']))
81
  G.eval()
82
+ return generate_images(
83
+ G,
84
+ SimpleNamespace(**{
85
+ 'truncation_psi': 0.7, #It seems like 0.7 will give the best result.
86
+ 'seeds': [seed],
87
+ 'batch_size': 1,
88
+ 'pixel_min': -1,
89
+ 'pixel_max': 1,
90
+ }) #https://github.com/adriansahlman/stylegan2_pytorch/blob/master/run_generator.py
91
+ )
92
 
93
  title = "TWDNEv3 CPU Generator"
94
  description = "Gradio Demo for TWDNEv3 CPU Generator (stylegan2_pytorch port). To use it, simply put your random seed."