Logan Zoellner commited on
Commit
241747c
β€’
1 Parent(s): 5fe351a

make seed take a string

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -14,8 +14,8 @@ import torch
14
  import torch.nn as nn
15
  from huggingface_hub import hf_hub_download
16
 
17
- if os.environ.get('SYSTEM') == 'spaces':
18
- subprocess.call('git apply ../patch'.split(), cwd='stylegan2-pytorch')
19
 
20
  sys.path.insert(0, 'stylegan2-pytorch')
21
 
@@ -27,11 +27,7 @@ The model used here is the one converted from the model provided in [this site](
27
 
28
  Expected execution time on Hugging Face Spaces: 4s
29
 
30
- Related Apps:
31
- - [TADNE Image Viewer](https://huggingface.co/spaces/hysts/TADNE-image-viewer)
32
- - [TADNE Image Selector](https://huggingface.co/spaces/hysts/TADNE-image-selector)
33
- - [TADNE Interpolation](https://huggingface.co/spaces/hysts/TADNE-interpolation)
34
- - [TADNE Image Search with DeepDanbooru](https://huggingface.co/spaces/hysts/TADNE-image-search-with-DeepDanbooru)
35
  '''
36
  SAMPLE_IMAGE_DIR = 'https://huggingface.co/spaces/hysts/TADNE/resolve/main/samples'
37
  ARTICLE = f'''## Generated images
@@ -40,7 +36,6 @@ ARTICLE = f'''## Generated images
40
  - seed: 0-99
41
  ![samples]({SAMPLE_IMAGE_DIR}/sample.jpg)
42
 
43
- <center><img src="https://visitor-badge.glitch.me/badge?page_id=hysts.tadne" alt="visitor badge"/></center>
44
  '''
45
 
46
  TOKEN = os.environ['TOKEN']
@@ -82,11 +77,15 @@ def generate_z(z_dim: int, seed: int, device: torch.device) -> torch.Tensor:
82
 
83
 
84
  @torch.inference_mode()
85
- def generate_image(seed: int, truncation_psi: float, randomize_noise: bool,
86
  model: nn.Module, device: torch.device) -> np.ndarray:
87
  seed = int(np.clip(seed, 0, np.iinfo(np.uint32).max))
88
 
89
- z = generate_z(model.style_dim, seed, device)
 
 
 
 
90
  out, _ = model([z],
91
  truncation=truncation_psi,
92
  truncation_latent=model.latent_avg,
@@ -107,7 +106,7 @@ def main():
107
  gr.Interface(
108
  func,
109
  [
110
- gr.inputs.Number(default=55376, label='Seed'),
111
  gr.inputs.Slider(
112
  0, 2, step=0.05, default=0.7, label='Truncation psi'),
113
  gr.inputs.Checkbox(default=False, label='Randomize Noise'),
 
14
  import torch.nn as nn
15
  from huggingface_hub import hf_hub_download
16
 
17
+ #if os.environ.get('SYSTEM') == 'spaces':
18
+ # subprocess.call('git apply ../patch'.split(), cwd='stylegan2-pytorch')
19
 
20
  sys.path.insert(0, 'stylegan2-pytorch')
21
 
 
27
 
28
  Expected execution time on Hugging Face Spaces: 4s
29
 
30
+ Based off of [hysts/TADNE](https://huggingface.co/spaces/hysts/TADNE)
 
 
 
 
31
  '''
32
  SAMPLE_IMAGE_DIR = 'https://huggingface.co/spaces/hysts/TADNE/resolve/main/samples'
33
  ARTICLE = f'''## Generated images
 
36
  - seed: 0-99
37
  ![samples]({SAMPLE_IMAGE_DIR}/sample.jpg)
38
 
 
39
  '''
40
 
41
  TOKEN = os.environ['TOKEN']
 
77
 
78
 
79
  @torch.inference_mode()
80
+ def generate_image(seed: str, truncation_psi: float, randomize_noise: bool,
81
  model: nn.Module, device: torch.device) -> np.ndarray:
82
  seed = int(np.clip(seed, 0, np.iinfo(np.uint32).max))
83
 
84
+ arr=bytearray.fromhex(seed[2:])
85
+ z = np.random.RandomState(arr).randn(n_sample, inputSize).astype("float32")
86
+
87
+ #z = generate_z(model.style_dim, seed, device)
88
+
89
  out, _ = model([z],
90
  truncation=truncation_psi,
91
  truncation_latent=model.latent_avg,
 
106
  gr.Interface(
107
  func,
108
  [
109
+ gr.inputs.String(default="0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984", label='Seed'),
110
  gr.inputs.Slider(
111
  0, 2, step=0.05, default=0.7, label='Truncation psi'),
112
  gr.inputs.Checkbox(default=False, label='Randomize Noise'),