Spaces:
Build error
Build error
neverix
commited on
Commit
•
4b0990a
1
Parent(s):
cd3dd7d
Big UI overhaul
Browse files- app.py +40 -5
- pulsar_clip.py +62 -53
app.py
CHANGED
@@ -24,11 +24,46 @@ def generate(*args):
|
|
24 |
|
25 |
|
26 |
def main():
|
27 |
-
gr.
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
|
34 |
if __name__ == '__main__':
|
|
|
24 |
|
25 |
|
26 |
def main():
|
27 |
+
with gr.Blocks() as ui:
|
28 |
+
gr.Markdown("# Pulsar+CLIP")
|
29 |
+
gr.Markdown("Generate 3D point clouds from text!")
|
30 |
+
|
31 |
+
with gr.Group():
|
32 |
+
gr.Markdown("## Settings")
|
33 |
+
inputs = []
|
34 |
+
with gr.Tabs():
|
35 |
+
for name, section in CONFIG_SPEC:
|
36 |
+
with gr.TabItem(name):
|
37 |
+
for k, v0, t in section:
|
38 |
+
if t in (float, int):
|
39 |
+
element = gr.Number(label=k, value=v0)
|
40 |
+
elif t == str:
|
41 |
+
element = gr.Textbox(label=k, value=v0)
|
42 |
+
elif t == bool:
|
43 |
+
element = gr.Checkbox(label=k, value=v0)
|
44 |
+
elif isinstance(t, tuple):
|
45 |
+
element = gr.Slider(*t, label=k, value=v0)
|
46 |
+
elif isinstance(t, list):
|
47 |
+
element = gr.Dropdown(label=k, value=v0, choices=t)
|
48 |
+
else:
|
49 |
+
raise TypeError(f"Input format {t} should be one of str, int, bool, tuple, list")
|
50 |
+
element = 1/0
|
51 |
+
inputs.append(element)
|
52 |
+
button = gr.Button("Run")
|
53 |
+
gr.Markdown("## Result")
|
54 |
+
output = gr.Video()
|
55 |
+
|
56 |
+
button.click(fn=generate,
|
57 |
+
inputs=inputs,
|
58 |
+
outputs=[output])
|
59 |
+
|
60 |
+
ui.launch()
|
61 |
+
|
62 |
+
#gr.Interface(inputs=[
|
63 |
+
#(gr.inputs.Number(label=k, default=v0) if t in (float, int) else
|
64 |
+
#gr.inputs.Checkbox(label=k, default=v0) if t == bool else gr.inputs.Textbox(label=k, default=v0) if t == str
|
65 |
+
#else gr.inputs.Dropdown(label=k, default=v0, choices=t) if isinstance(t, (tuple, list)) else 1/0)
|
66 |
+
#for k, v0, t in CONFIG_SPEC], outputs=gr.outputs.Video(), fn=generate).launch()
|
67 |
|
68 |
|
69 |
if __name__ == '__main__':
|
pulsar_clip.py
CHANGED
@@ -8,58 +8,67 @@ import torch
|
|
8 |
|
9 |
|
10 |
CONFIG_SPEC = [
|
11 |
-
("
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
("
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
("
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
("
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
]
|
60 |
|
61 |
|
62 |
# TODO: one day separate the config into multiple parts and split this megaobject into multiple objects
|
|
|
63 |
class PulsarCLIP(object):
|
64 |
def __init__(self, args):
|
65 |
args = DotDict(**args)
|
@@ -208,11 +217,11 @@ class PulsarCLIP(object):
|
|
208 |
self.scheduler.step()
|
209 |
except AttributeError:
|
210 |
pass
|
211 |
-
if i % self.args.show_every == 0:
|
212 |
-
cam_params = self.camera(i / self.args.iterations * np.pi * 2 * self.args.turns, use_random=False)
|
213 |
-
img_show, _ = self.render(cam_params)
|
214 |
-
img = Image.fromarray((img_show.cpu().detach().numpy() * 255).astype(np.uint8))
|
215 |
-
yield img
|
216 |
except KeyboardInterrupt:
|
217 |
pass
|
218 |
|
|
|
8 |
|
9 |
|
10 |
CONFIG_SPEC = [
|
11 |
+
("General", [
|
12 |
+
("text", "A cloud at dawn", str),
|
13 |
+
("iterations", 5000, (0, 7500)),
|
14 |
+
("seed", 12, int),
|
15 |
+
]),
|
16 |
+
("Rendering", [
|
17 |
+
("w", 224, [224, 252]),
|
18 |
+
("h", 224, [224, 252]),
|
19 |
+
# ("show_every", 50, int),
|
20 |
+
("showoff", 5000, (0, 10000)),
|
21 |
+
("turns", 4, int),
|
22 |
+
("focal_length", 0.1, float),
|
23 |
+
("plane_width", 0.1, float),
|
24 |
+
("shade_strength", 0.25, float),
|
25 |
+
("gamma", 0.5, float),
|
26 |
+
("max_depth", 7, float),
|
27 |
+
("offset", 5, float),
|
28 |
+
("offset_random", 0.75, float),
|
29 |
+
("xyz_random", 0.25, float),
|
30 |
+
("altitude_range", 0.3, float),
|
31 |
+
("augments", 4, int),
|
32 |
+
]),
|
33 |
+
("Optimization", [
|
34 |
+
("epochs", 1, int),
|
35 |
+
("lr", 0.5, float),
|
36 |
+
#@markdown CLIP loss type, might improve the results
|
37 |
+
("loss_type", "spherical", ["spherical", "cosine"]),
|
38 |
+
#@markdown CLIP loss weight
|
39 |
+
("clip_weight", 1.0, float), #@param {type: "number"}
|
40 |
+
]),
|
41 |
+
("Elements", [
|
42 |
+
("num_objects", 256, int),
|
43 |
+
#@markdown Number of dimensions. 0 is for point clouds (default), 1 will make
|
44 |
+
#@markdown strokes, 2 will make planes, 3 produces little cubes
|
45 |
+
("ndim", 0, [0, 1, 2, 3]), #@param {type: "integer"}
|
46 |
+
|
47 |
+
#@markdown Opacity scale:
|
48 |
+
("min_opacity", 1e-4, float), #@param {type: "number"}
|
49 |
+
("max_opacity", 1.0, float), #@param {type: "number"}
|
50 |
+
("log_opacity", False, bool), #@param {type: "boolean"}
|
51 |
+
|
52 |
+
("min_radius", 0.030, float),
|
53 |
+
("max_radius", 0.070, float),
|
54 |
+
("log_radius", False, bool),
|
55 |
+
|
56 |
+
# TODO dynamically decide bezier_res
|
57 |
+
#@markdown Bezier resolution: how many points a line/plane/cube will have. Not applicable to points
|
58 |
+
("bezier_res", 8, int), #@param {type: "integer"}
|
59 |
+
#@markdown Maximum scale of parameters: position, velocity, acceleration
|
60 |
+
("pos_scale", 0.4, float), #@param {type: "number"}
|
61 |
+
("vel_scale", 0.15, float), #@param {type: "number"}
|
62 |
+
("acc_scale", 0.15, float), #@param {type: "number"}
|
63 |
+
|
64 |
+
#@markdown Scale of each individual 3D object. Master control for velocity and acceleration scale.
|
65 |
+
("scale", 1, float), #@param {type: "number"}
|
66 |
+
]),
|
67 |
]
|
68 |
|
69 |
|
70 |
# TODO: one day separate the config into multiple parts and split this megaobject into multiple objects
|
71 |
+
# 2022/08/09: halfway done
|
72 |
class PulsarCLIP(object):
|
73 |
def __init__(self, args):
|
74 |
args = DotDict(**args)
|
|
|
217 |
self.scheduler.step()
|
218 |
except AttributeError:
|
219 |
pass
|
220 |
+
#if i % self.args.show_every == 0:
|
221 |
+
#cam_params = self.camera(i / self.args.iterations * np.pi * 2 * self.args.turns, use_random=False)
|
222 |
+
#img_show, _ = self.render(cam_params)
|
223 |
+
#img = Image.fromarray((img_show.cpu().detach().numpy() * 255).astype(np.uint8))
|
224 |
+
#yield img
|
225 |
except KeyboardInterrupt:
|
226 |
pass
|
227 |
|