ldkong commited on
Commit
994c3d0
·
1 Parent(s): 6db2d7c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -45
app.py CHANGED
@@ -1,49 +1,20 @@
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
- gr.Interface(
42
- predict,
43
- inputs=[
44
- gr.Slider(0, 1000, label='Seed', default=42),
45
- gr.Slider(4, 64, label='Number of Punks', step=1, default=10),
46
- ],
47
- outputs="image",
48
- examples=[[123, 15], [42, 29], [456, 8], [1337, 35]],
49
- ).launch(cache_examples=True)
 
 
 
 
 
1
  import gradio as gr
2
 
3
+ def calculator(num1, operation, num2):
4
+ if operation == "add":
5
+ return num1 + num2
6
+ elif operation == "subtract":
7
+ return num1 - num2
8
+ elif operation == "multiply":
9
+ return num1 * num2
10
+ elif operation == "divide":
11
+ return num1 / num2
 
 
 
 
 
 
 
 
 
12
 
13
+ demo = gr.Interface(
14
+ calculator,
15
+ ["number", gr.Radio(["add", "subtract", "multiply", "divide"]), "number"],
16
+ "number",
17
+ live=True,
18
+ )
19
 
20
+ demo.launch()