Spaces:
Runtime error
Runtime error
osanseviero
commited on
Commit
•
cbcafc2
1
Parent(s):
9c19948
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
import torch
|
5 |
+
from tqdm.auto import tqdm
|
6 |
+
|
7 |
+
from point_e.diffusion.configs import DIFFUSION_CONFIGS, diffusion_from_config
|
8 |
+
from point_e.diffusion.sampler import PointCloudSampler
|
9 |
+
from point_e.models.download import load_checkpoint
|
10 |
+
from point_e.models.configs import MODEL_CONFIGS, model_from_config
|
11 |
+
from point_e.util.plotting import plot_point_cloud
|
12 |
+
|
13 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
14 |
+
|
15 |
+
print('creating base model...')
|
16 |
+
base_name = 'base40M-textvec'
|
17 |
+
base_model = model_from_config(MODEL_CONFIGS[base_name], device)
|
18 |
+
base_model.eval()
|
19 |
+
base_diffusion = diffusion_from_config(DIFFUSION_CONFIGS[base_name])
|
20 |
+
|
21 |
+
print('creating upsample model...')
|
22 |
+
upsampler_model = model_from_config(MODEL_CONFIGS['upsample'], device)
|
23 |
+
upsampler_model.eval()
|
24 |
+
upsampler_diffusion = diffusion_from_config(DIFFUSION_CONFIGS['upsample'])
|
25 |
+
|
26 |
+
print('downloading base checkpoint...')
|
27 |
+
base_model.load_state_dict(load_checkpoint(base_name, device))
|
28 |
+
|
29 |
+
print('downloading upsampler checkpoint...')
|
30 |
+
upsampler_model.load_state_dict(load_checkpoint('upsample', device))
|
31 |
+
|
32 |
+
sampler = PointCloudSampler(
|
33 |
+
device=device,
|
34 |
+
models=[base_model, upsampler_model],
|
35 |
+
diffusions=[base_diffusion, upsampler_diffusion],
|
36 |
+
num_points=[1024, 4096 - 1024],
|
37 |
+
aux_channels=['R', 'G', 'B'],
|
38 |
+
guidance_scale=[3.0, 0.0],
|
39 |
+
model_kwargs_key_filter=('texts', ''), # Do not condition the upsampler at all
|
40 |
+
)
|
41 |
+
|
42 |
+
def inference(prompt):
|
43 |
+
samples = None
|
44 |
+
for x in sampler.sample_batch_progressive(batch_size=1, model_kwargs=dict(texts=[prompt])):
|
45 |
+
samples = x
|
46 |
+
pc = sampler.output_to_point_clouds(samples)[0]
|
47 |
+
pc = sampler.output_to_point_clouds(samples)[0]
|
48 |
+
fig = plot_point_cloud(pc, grid_size=3, fixed_bounds=((-0.75, -0.75, -0.75),(0.75, 0.75, 0.75)))
|
49 |
+
return fig
|
50 |
+
|
51 |
+
demo = gr.Interface(fn=inference, inputs="text", outputs=gr.Plot())
|
52 |
+
demo.launch(debug=True)
|