File size: 2,386 Bytes
5ea1b6f ede25fc 5ea1b6f ede25fc 5ea1b6f ede25fc 5ea1b6f ede25fc 5ea1b6f ede25fc 5ea1b6f ede25fc 5ea1b6f ede25fc 5ea1b6f 45cdafe 5ea1b6f 45cdafe 5ea1b6f 65555e4 5ea1b6f 65555e4 5ea1b6f 65555e4 5ea1b6f 65555e4 5ea1b6f 65555e4 32ff3c8 5ea1b6f 32ff3c8 5ea1b6f 32ff3c8 5ea1b6f 32ff3c8 5ea1b6f 32ff3c8 5ea1b6f ede25fc 5ea1b6f ede25fc |
1 2 3 4 5 6 7 8 9 10 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
import gradio as gr
import pickle
# from datasets import load_from_disk
from plaid.containers.sample import Sample
# import pyvista as pv
import pyrender
import trimesh
import matplotlib.pyplot as plt
import os
# switch to "osmesa" or "egl" before loading pyrender
os.environ["PYOPENGL_PLATFORM"] = "egl"
import numpy as np
# FOLDER = "plot"
# dataset = load_from_disk("Rotor37")
field_names_train = ["Temperature", "Pressure", "Density"]#pickle.loads(dataset[0]["sample"]).get_field_names()
field_names_test = []
def sample_info(sample_id_str, fieldn):
# sample_id = int(sample_id_str)
# plaid_sample = Sample.load_from_dir(f"Rotor37/dataset/samples/sample_"+str(sample_id_str).zfill(9))
str__ = f"loading sample {sample_id_str}"
# generate mesh
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)
# compose scene
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]])
# render scene
# 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"
return str__, str__
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.Text(label="Training sample visualization")
# output2 = gr.Image(label="Training sample visualization")
# d1.input(update_second, d1, d2)
d1.input(sample_info, [d1, d2], [output1, output2])
d2.input(sample_info, [d1, d2], [output1, output2])
demo.launch()
|