Chun-Hao Liu commited on
Commit
c79dec1
·
1 Parent(s): 86b88bb

multiple testing gradio apps

Browse files
Files changed (2) hide show
  1. app2.py +14 -0
  2. app3.py +51 -0
app2.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import login
3
+
4
+ description = "BigGAN text-to-image demo."
5
+
6
+ title = "BigGAN ImageNet"
7
+
8
+ interface = gr.Interface.load("huggingface/osanseviero/BigGAN-deep-128",
9
+ description=description,
10
+ title = title,
11
+ examples=[["american robin"]]
12
+ )
13
+
14
+ interface.launch()
app3.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from torch import nn
3
+ from huggingface_hub import hf_hub_download
4
+ from torchvision.utils import save_image
5
+ import gradio as gr
6
+
7
+ class Generator(nn.Module):
8
+ # Refer to the link below for explanations about nc, nz, and ngf
9
+ # https://pytorch.org/tutorials/beginner/dcgan_faces_tutorial.html#inputs
10
+ def __init__(self, nc=4, nz=100, ngf=64):
11
+ super(Generator, self).__init__()
12
+ self.network = nn.Sequential(
13
+ nn.ConvTranspose2d(nz, ngf * 4, 3, 1, 0, bias=False),
14
+ nn.BatchNorm2d(ngf * 4),
15
+ nn.ReLU(True),
16
+ nn.ConvTranspose2d(ngf * 4, ngf * 2, 3, 2, 1, bias=False),
17
+ nn.BatchNorm2d(ngf * 2),
18
+ nn.ReLU(True),
19
+ nn.ConvTranspose2d(ngf * 2, ngf, 4, 2, 0, bias=False),
20
+ nn.BatchNorm2d(ngf),
21
+ nn.ReLU(True),
22
+ nn.ConvTranspose2d(ngf, nc, 4, 2, 1, bias=False),
23
+ nn.Tanh(),
24
+ )
25
+
26
+ def forward(self, input):
27
+ output = self.network(input)
28
+ return output
29
+
30
+ model = Generator()
31
+ weights_path = hf_hub_download('nateraw/cryptopunks-gan', 'generator.pth')
32
+ model.load_state_dict(torch.load(weights_path, map_location=torch.device('cpu'))) # Use 'cuda' if you have a GPU available
33
+
34
+ def predict(seed, num_punks):
35
+ torch.manual_seed(seed)
36
+ z = torch.randn(num_punks, 100, 1, 1)
37
+ punks = model(z)
38
+ save_image(punks, "punks.png", normalize=True)
39
+ return 'punks.png'
40
+
41
+ demo = gr.Interface(
42
+ predict,
43
+ inputs=[
44
+ gr.Slider(0, 1000, label='Seed', value=42),
45
+ gr.Slider(4, 64, label='Number of Punks', step=1, value=10),
46
+ ],
47
+ outputs="image",
48
+ examples=[[123, 15], [42, 29], [456, 8], [1337, 35]],
49
+ )
50
+
51
+ demo.launch(share=True)