Update app.py
Browse files
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 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 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 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|