Files changed (1) hide show
  1. app.py +0 -85
app.py DELETED
@@ -1,85 +0,0 @@
1
- import gradio as gr
2
- import plotly.graph_objects as go
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
- colors=(238, 75, 43)
49
- fig = go.Figure(
50
- data=[
51
- go.Scatter3d(
52
- x=pc.coords[:,0], y=pc.coords[:,1], z=pc.coords[:,2],
53
- mode='markers',
54
- marker=dict(
55
- size=2,
56
- color=['rgb({},{},{})'.format(r,g,b) for r,g,b in zip(pc.channels["R"], pc.channels["G"], pc.channels["B"])],
57
- )
58
- )
59
- ],
60
- layout=dict(
61
- scene=dict(
62
- xaxis=dict(visible=False),
63
- yaxis=dict(visible=False),
64
- zaxis=dict(visible=False)
65
- )
66
- ),
67
- )
68
- return fig
69
-
70
- demo = gr.Interface(
71
- fn=inference,
72
- inputs="text",
73
- outputs=gr.Plot(),
74
- examples=[
75
- ["a red motorcycle"],
76
- ["a RED pumpkin"],
77
- ["a yellow rubber duck"]
78
- ],
79
- title="Point-E demo: text to 3D",
80
- description="""Generated 3D Point Cloiuds with [Point-E](https://github.com/openai/point-e/tree/main). This demo uses a small, worse quality text-to-3D model to produce 3D point clouds directly from text descriptions.
81
- Check out the [notebook](https://github.com/openai/point-e/blob/main/point_e/examples/text2pointcloud.ipynb).
82
- """
83
- )
84
- demo.queue(max_size=30)
85
- demo.launch(debug=True)