Spaces:
Sleeping
Sleeping
fabiencasenave
commited on
Commit
•
5ea1b6f
1
Parent(s):
ede25fc
Update app.py
Browse files
app.py
CHANGED
@@ -1,59 +1,87 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
#
|
|
|
|
|
4 |
|
5 |
-
|
6 |
-
|
|
|
7 |
|
8 |
-
|
9 |
-
#
|
10 |
-
|
11 |
|
12 |
-
|
13 |
|
14 |
-
#
|
15 |
-
# bg_color=[1.0, 1.0, 1.0])
|
16 |
|
17 |
-
#
|
18 |
-
# color, depth = r.render(scene)
|
19 |
|
20 |
-
#
|
21 |
-
|
22 |
|
23 |
|
24 |
-
import os
|
25 |
-
# switch to "osmesa" or "egl" before loading pyrender
|
26 |
-
os.environ["PYOPENGL_PLATFORM"] = "egl"
|
27 |
|
28 |
-
import numpy as np
|
29 |
-
import pyrender
|
30 |
-
import trimesh
|
31 |
-
import matplotlib.pyplot as plt
|
32 |
|
33 |
-
# generate mesh
|
34 |
-
sphere = trimesh.creation.icosphere(subdivisions=4, radius=0.8)
|
35 |
-
sphere.vertices+=1e-2*np.random.randn(*sphere.vertices.shape)
|
36 |
-
mesh = pyrender.Mesh.from_trimesh(sphere, smooth=False)
|
37 |
|
38 |
-
# compose scene
|
39 |
-
scene = pyrender.Scene(ambient_light=[.1, .1, .3], bg_color=[0, 0, 0])
|
40 |
-
camera = pyrender.PerspectiveCamera( yfov=np.pi / 3.0)
|
41 |
-
light = pyrender.DirectionalLight(color=[1,1,1], intensity=2e3)
|
42 |
|
43 |
-
scene.add(mesh, pose= np.eye(4))
|
44 |
-
scene.add(light, pose= np.eye(4))
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
# render scene
|
53 |
-
r = pyrender.OffscreenRenderer(512, 512)
|
54 |
-
color, _ = r.render(scene)
|
55 |
|
56 |
-
|
57 |
-
plt.imshow(color)
|
58 |
|
59 |
-
plt.savefig("test.png")
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pickle
|
3 |
+
# from datasets import load_from_disk
|
4 |
+
from plaid.containers.sample import Sample
|
5 |
+
# import pyvista as pv
|
6 |
|
7 |
+
import pyrender
|
8 |
+
import trimesh
|
9 |
+
import matplotlib.pyplot as plt
|
10 |
|
11 |
+
import os
|
12 |
+
# switch to "osmesa" or "egl" before loading pyrender
|
13 |
+
os.environ["PYOPENGL_PLATFORM"] = "egl"
|
14 |
|
15 |
+
import numpy as np
|
16 |
|
17 |
+
# FOLDER = "plot"
|
|
|
18 |
|
19 |
+
# dataset = load_from_disk("Rotor37")
|
|
|
20 |
|
21 |
+
field_names_train = ["Temperature", "Pressure", "Density"]#pickle.loads(dataset[0]["sample"]).get_field_names()
|
22 |
+
field_names_test = []
|
23 |
|
24 |
|
|
|
|
|
|
|
25 |
|
|
|
|
|
|
|
|
|
26 |
|
|
|
|
|
|
|
|
|
27 |
|
|
|
|
|
|
|
|
|
28 |
|
|
|
|
|
29 |
|
30 |
+
def sample_info(sample_id_str, fieldn):
|
31 |
+
|
32 |
+
sample_id = int(sample_id_str)
|
33 |
+
|
34 |
+
plaid_sample = Sample.load_from_dir(f"Rotor37/dataset/samples/sample_"+str(sample_id_str).zfill(9))
|
35 |
+
|
36 |
+
|
37 |
+
# generate mesh
|
38 |
+
sphere = trimesh.creation.icosphere(subdivisions=4, radius=0.8)
|
39 |
+
sphere.vertices+=1e-2*np.random.randn(*sphere.vertices.shape)
|
40 |
+
mesh = pyrender.Mesh.from_trimesh(sphere, smooth=False)
|
41 |
+
|
42 |
+
# compose scene
|
43 |
+
scene = pyrender.Scene(ambient_light=[.1, .1, .3], bg_color=[0, 0, 0])
|
44 |
+
camera = pyrender.PerspectiveCamera( yfov=np.pi / 3.0)
|
45 |
+
light = pyrender.DirectionalLight(color=[1,1,1], intensity=2e3)
|
46 |
+
|
47 |
+
scene.add(mesh, pose= np.eye(4))
|
48 |
+
scene.add(light, pose= np.eye(4))
|
49 |
+
|
50 |
+
c = 2**-0.5
|
51 |
+
scene.add(camera, pose=[[ 1, 0, 0, 0],
|
52 |
+
[ 0, c, -c, -2],
|
53 |
+
[ 0, c, c, 2],
|
54 |
+
[ 0, 0, 0, 1]])
|
55 |
+
|
56 |
+
# render scene
|
57 |
+
r = pyrender.OffscreenRenderer(512, 512)
|
58 |
+
color, _ = r.render(scene)
|
59 |
+
|
60 |
+
plt.figure(figsize=(8,8))
|
61 |
+
plt.imshow(color)
|
62 |
+
|
63 |
+
plt.savefig("test.png")
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
return str__, "test.png"
|
68 |
+
|
69 |
+
|
70 |
+
if __name__ == "__main__":
|
71 |
+
|
72 |
+
with gr.Blocks() as demo:
|
73 |
+
d1 = gr.Slider(0, 999, value=0, label="Training sample id", info="Choose between 0 and 999")
|
74 |
+
d2 = gr.Dropdown(field_names_train, value=field_names_train[0], label="Field name")
|
75 |
+
|
76 |
+
|
77 |
+
output1 = gr.Text(label="Training sample info")
|
78 |
+
output2 = gr.Image(label="Training sample visualization")
|
79 |
+
|
80 |
+
# d1.input(update_second, d1, d2)
|
81 |
+
|
82 |
+
d1.input(sample_info, [d1, d2], [output1, output2])
|
83 |
+
d2.input(sample_info, [d1, d2], [output1, output2])
|
84 |
|
|
|
|
|
|
|
85 |
|
86 |
+
demo.launch()
|
|
|
87 |
|
|