Upload 4 files
Browse files- README.md +4 -6
- app.py +50 -0
- requirements.txt +2 -0
- weights.pt +3 -0
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 5.12.0
|
8 |
app_file: app.py
|
@@ -10,5 +10,3 @@ pinned: false
|
|
10 |
license: mit
|
11 |
short_description: a GAN trained on the first 40k images of CrypkoHQ dataset
|
12 |
---
|
13 |
-
|
14 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: Crypko GAN
|
3 |
+
emoji: 🦋
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: purple
|
6 |
sdk: gradio
|
7 |
sdk_version: 5.12.0
|
8 |
app_file: app.py
|
|
|
10 |
license: mit
|
11 |
short_description: a GAN trained on the first 40k images of CrypkoHQ dataset
|
12 |
---
|
|
|
|
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
import torch.nn as nn
|
4 |
+
|
5 |
+
def Generator():
|
6 |
+
up_conv_block = lambda c_in, c_out: [
|
7 |
+
nn.Upsample(None, 2, 'bilinear'),
|
8 |
+
nn.LeakyReLU(0.1, True),
|
9 |
+
nn.Conv2d(c_in, c_in, 3, 1, 1),
|
10 |
+
nn.LeakyReLU(0.1, True),
|
11 |
+
nn.Conv2d(c_in, c_in, 3, 1, 1),
|
12 |
+
nn.LeakyReLU(0.1, True),
|
13 |
+
nn.Conv2d(c_in, c_out, 3, 1, 1),
|
14 |
+
]
|
15 |
+
return nn.Sequential(
|
16 |
+
nn.Linear(256, 1024),
|
17 |
+
nn.LeakyReLU(0.1, True),
|
18 |
+
nn.Linear(1024, 9216),
|
19 |
+
nn.LayerNorm(9216, 1e-6, False),
|
20 |
+
nn.Unflatten(1, (1024, 3, 3)),
|
21 |
+
*up_conv_block(1024, 512),
|
22 |
+
*up_conv_block(512, 256),
|
23 |
+
*up_conv_block(256, 128),
|
24 |
+
*up_conv_block(128, 64),
|
25 |
+
*up_conv_block(64, 3),
|
26 |
+
nn.Sigmoid(),
|
27 |
+
)
|
28 |
+
|
29 |
+
model = Generator().requires_grad_(False).eval()
|
30 |
+
model.load_state_dict(torch.load('weights.pt'))
|
31 |
+
p = 2147483647
|
32 |
+
|
33 |
+
def gen(state):
|
34 |
+
state = max(round(state), 1)
|
35 |
+
x = torch.empty(1, 256, dtype=torch.float64)
|
36 |
+
for i in range(256):
|
37 |
+
state = state * 48271 % p
|
38 |
+
x[0, i] = float(state) / p
|
39 |
+
x = torch.special.ndtri(x).float()
|
40 |
+
y = model(x).mul(255).round().byte()
|
41 |
+
img = y[0].permute(1, 2, 0).numpy()
|
42 |
+
return state, img
|
43 |
+
|
44 |
+
with gr.Blocks() as demo:
|
45 |
+
state_slider = gr.Slider(1, p - 1, 4, step=1, label='PRNG State')
|
46 |
+
img_output = gr.Image(label="Generated Image", format='png')
|
47 |
+
click_btn = gr.Button('Generate')
|
48 |
+
click_btn.click(fn=gen, inputs=state_slider, outputs=[state_slider, img_output])
|
49 |
+
|
50 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
numpy<2
|
2 |
+
torch
|
weights.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:74a2f72c3a5b3f871fde063dded4817de266e02abcf62cbeb8973312416ae348
|
3 |
+
size 82259874
|