|
import gradio as gr |
|
import pickle |
|
|
|
from plaid.containers.sample import Sample |
|
|
|
|
|
import pyrender |
|
import trimesh |
|
import matplotlib.pyplot as plt |
|
|
|
import os |
|
|
|
os.environ["PYOPENGL_PLATFORM"] = "egl" |
|
|
|
import numpy as np |
|
|
|
|
|
|
|
|
|
|
|
field_names_train = ["Temperature", "Pressure", "Density"] |
|
field_names_test = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def sample_info(sample_id_str, fieldn): |
|
|
|
|
|
|
|
|
|
str__ = f"loading sample {sample_id_str}" |
|
|
|
|
|
|
|
sphere = trimesh.creation.icosphere(subdivisions=4, radius=0.8) |
|
sphere.vertices+=1e-2*np.random.randn(*sphere.vertices.shape) |
|
mesh = pyrender.Mesh.from_trimesh(sphere, smooth=False) |
|
|
|
|
|
scene = pyrender.Scene(ambient_light=[.1, .1, .3], bg_color=[0, 0, 0]) |
|
camera = pyrender.PerspectiveCamera( yfov=np.pi / 3.0) |
|
light = pyrender.DirectionalLight(color=[1,1,1], intensity=2e3) |
|
|
|
scene.add(mesh, pose= np.eye(4)) |
|
scene.add(light, pose= np.eye(4)) |
|
|
|
c = 2**-0.5 |
|
scene.add(camera, pose=[[ 1, 0, 0, 0], |
|
[ 0, c, -c, -2], |
|
[ 0, c, c, 2], |
|
[ 0, 0, 0, 1]]) |
|
|
|
|
|
r = pyrender.OffscreenRenderer(512, 512) |
|
color, _ = r.render(scene) |
|
|
|
|
|
plt.figure(figsize=(8,8)) |
|
plt.imshow(color) |
|
|
|
plt.savefig("test.png") |
|
|
|
|
|
|
|
return str__, "test.png" |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
with gr.Blocks() as demo: |
|
d1 = gr.Slider(0, 999, value=0, label="Training sample id", info="Choose between 0 and 999") |
|
d2 = gr.Dropdown(field_names_train, value=field_names_train[0], label="Field name") |
|
|
|
|
|
output1 = gr.Text(label="Training sample info") |
|
|
|
output2 = gr.Image(label="Training sample visualization") |
|
|
|
|
|
|
|
d1.input(sample_info, [d1, d2], [output1, output2]) |
|
d2.input(sample_info, [d1, d2], [output1, output2]) |
|
|
|
|
|
demo.launch() |
|
|
|
|