Spaces:
Runtime error
Runtime error
Commit
·
2bea005
1
Parent(s):
a0be46c
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torchvision
|
3 |
+
imp
|
4 |
+
ort torch
|
5 |
+
model = torch.hub.load(
|
6 |
+
"ndahlquist/pytorch-hub-stylegan:0.0.1",
|
7 |
+
"style_gan",
|
8 |
+
pretrained=True)
|
9 |
+
def iface(name):
|
10 |
+
model.eval()
|
11 |
+
device = 'cuda:0' if torch.cuda.is_available() else 'cpu'
|
12 |
+
model.to(device)
|
13 |
+
latents = torch.randn(1, 512, device=device)
|
14 |
+
with torch.no_grad():
|
15 |
+
img = model(latents)
|
16 |
+
img = (img.clamp(-1, 1) + 1) / 2.0
|
17 |
+
img2=img.numpy()
|
18 |
+
img3=img2.squeeze()
|
19 |
+
img4 = img3.swapaxes(0,1)
|
20 |
+
img5=img4.swapaxes(1,2)
|
21 |
+
out= img5
|
22 |
+
return out
|
23 |
+
demo = gr.Interface(fn=iface,inputs='text', outputs='image')
|
24 |
+
demo.launch()
|
25 |
+
|