Thomas.Chaigneau commited on
Commit
3234a40
1 Parent(s): 6de6ae4

init main app

Browse files
Files changed (1) hide show
  1. main.py +36 -0
main.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import torchvision.transforms as T
4
+
5
+ from model import DocuGAN
6
+
7
+
8
+ chk_path = "best_model.ckpt"
9
+ model = DocuGAN(hidden_size=64, num_channel=1, latent_size=128, batch_size=128)
10
+ # model = DocuGAN.load_from_checkpoint(chk_path, strict=False)
11
+ model.eval()
12
+ transform = T.ToPILImage()
13
+
14
+
15
+ def fn(seed: int = 42):
16
+ torch.manual_seed(seed)
17
+ noise = torch.randn(1, 128, 1, 1)
18
+ with torch.no_grad():
19
+ pred = model(noise)
20
+ img = transform(pred.squeeze(1))
21
+ return img
22
+
23
+
24
+ gr.Interface(
25
+ fn,
26
+ inputs=[
27
+ gr.inputs.Slider(minimum=0, maximum=999999999, step=1, default=298422436, label='Random Seed')
28
+ ],
29
+ outputs='image',
30
+ examples=[],
31
+ enable_queue=True,
32
+ title="DocuGAN",
33
+ description="Select random seed and click on Submit to generate a new Document",
34
+ article="DocuGAN, Document Generator by ChainYo",
35
+ css=".panel { padding: 5px } .moflo-link { color: #999 }"
36
+ ).launch()