porestar commited on
Commit
376e39e
·
1 Parent(s): afed0d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -2,6 +2,9 @@ import gradio as gr
2
  import torch
3
  from diffusers.models import UNet2DModel
4
  from huggingface_hub import hf_hub_download
 
 
 
5
 
6
  path = hf_hub_download(repo_id="porestar/oadg_channels_64", filename="model.pt")
7
 
@@ -27,16 +30,22 @@ model = UNet2DModel(
27
 
28
  model.load_state_dict(torch.load(path, map_location=torch.device('cpu')))
29
 
 
 
30
 
31
- def classify_image(inp):
32
- return {"lol": 0}
33
 
 
 
34
 
35
- img = gr.Image(image_mode="L", source="canvas", shape=(32, 32), invert_colors=False)
36
- label = gr.Label(num_top_classes=3)
 
 
37
 
38
- demo = gr.Interface(
39
- fn=classify_image, inputs=img, outputs=label, interpretation="default"
40
- )
41
 
42
- demo.launch()
 
 
 
 
 
 
2
  import torch
3
  from diffusers.models import UNet2DModel
4
  from huggingface_hub import hf_hub_download
5
+ from oadg.sampling import sample, make_conditional_paths_and_realization
6
+
7
+ image_size = 64
8
 
9
  path = hf_hub_download(repo_id="porestar/oadg_channels_64", filename="model.pt")
10
 
 
30
 
31
  model.load_state_dict(torch.load(path, map_location=torch.device('cpu')))
32
 
33
+ device = 'cpu'
34
+ model = model.to(device)
35
 
 
 
36
 
37
+ def sample_image(img):
38
+ t_range_start, sigma_conditioned, realization = make_conditional_paths_and_realization(img, device=device)
39
 
40
+ img = sample(model, batch_size=16, image_size=image_size,
41
+ realization=realization, t_range_start=t_range_start, sigma_conditioned=sigma_conditioned, device=device)
42
+ img = img.reshape(4*image_size, 4*image_size)*255
43
+ return img
44
 
 
 
 
45
 
46
+ img = gr.Image(image_mode="L", source="canvas", shape=(image_size, image_size), invert_colors=True)
47
+ out = gr.Image(image_mode="L", shape=(image_size, image_size), invert_colors=True)
48
+
49
+ demo = gr.Interface(fn=sample_image, inputs=img, outputs=out)
50
+
51
+ demo.launch()