Update app.py
Browse files
app.py
CHANGED
@@ -15,32 +15,36 @@ import os
|
|
15 |
os.environ["PYOPENGL_PLATFORM"] = "egl"
|
16 |
|
17 |
|
18 |
-
hf_dataset = load_dataset("
|
19 |
-
|
|
|
|
|
20 |
|
21 |
ids_train = hf_dataset.description["split"]["train"]
|
22 |
nb_samples = len(ids_train)
|
23 |
|
24 |
|
25 |
-
field_names_train = ["
|
26 |
|
27 |
|
28 |
_HEADER_ = '''
|
29 |
-
<h2><b>Visualization demo of <a href='https://huggingface.co/datasets/PLAID-datasets/
|
30 |
'''
|
31 |
|
32 |
|
33 |
def round_num(num)->str:
|
34 |
return '%s' % float('%.3g' % num)
|
35 |
|
36 |
-
def sample_info(sample_id_str, fieldn):
|
|
|
|
|
37 |
|
38 |
sample_ = hf_dataset[ids_train[int(sample_id_str)]]["sample"]
|
39 |
plaid_sample = Sample.model_validate(pickle.loads(sample_))
|
40 |
# plaid_sample = Sample.load_from_dir(f"Tensile2d/dataset/samples/sample_"+str(sample_id_str).zfill(9))
|
41 |
|
42 |
-
nodes = plaid_sample.get_nodes()
|
43 |
-
field = plaid_sample.get_field(fieldn)
|
44 |
# if nodes.shape[1] == 2:
|
45 |
# nodes__ = np.zeros((nodes.shape[0],nodes.shape[1]+1))
|
46 |
# nodes__[:,:-1] = nodes
|
@@ -132,14 +136,16 @@ if __name__ == "__main__":
|
|
132 |
with gr.Row(variant="panel"):
|
133 |
with gr.Column(scale=1):
|
134 |
d1 = gr.Slider(0, nb_samples-1, value=0, label="Training sample id", info="Choose between 0 and "+str(nb_samples-1))
|
|
|
135 |
output1 = gr.Text(label="Training sample info")
|
136 |
with gr.Column(scale=2, min_width=300):
|
137 |
-
|
138 |
# output2 = gr.Image(label="Training sample visualization")
|
139 |
output2 = gr.Model3D(label="Training sample visualization")
|
140 |
|
141 |
-
d1.input(sample_info, [d1, d2], [output1, output2])
|
142 |
-
d2.input(sample_info, [d1, d2], [output1, output2])
|
|
|
143 |
|
144 |
demo.launch()
|
145 |
|
|
|
15 |
os.environ["PYOPENGL_PLATFORM"] = "egl"
|
16 |
|
17 |
|
18 |
+
hf_dataset = load_dataset("fabiencasenave/2D_ElastoPlastoDynamics", split="all_samples")
|
19 |
+
sample0 = hf_dataset[0]["sample"]
|
20 |
+
plaid_sample0 = Sample.model_validate(pickle.loads(sample_))
|
21 |
+
times_steps = list(plaid_sample0._meshes.keys())
|
22 |
|
23 |
ids_train = hf_dataset.description["split"]["train"]
|
24 |
nb_samples = len(ids_train)
|
25 |
|
26 |
|
27 |
+
field_names_train = ["U_x", "U_y", "Sigma_xx", "Sigma_xy", "Sigma_yy", "Epsilon_xx", "Epsilon_xy", "Epsilon_yy", "EROSION_STATUS"]
|
28 |
|
29 |
|
30 |
_HEADER_ = '''
|
31 |
+
<h2><b>Visualization demo of <a href='https://huggingface.co/datasets/PLAID-datasets/2D_ElastoPlastoDynamics' target='_blank'><b>2D_profile 2D_ElastoPlastoDynamics</b></b></h2>
|
32 |
'''
|
33 |
|
34 |
|
35 |
def round_num(num)->str:
|
36 |
return '%s' % float('%.3g' % num)
|
37 |
|
38 |
+
def sample_info(sample_id_str, time_step, fieldn):
|
39 |
+
|
40 |
+
time = times_steps[int(time_step)]
|
41 |
|
42 |
sample_ = hf_dataset[ids_train[int(sample_id_str)]]["sample"]
|
43 |
plaid_sample = Sample.model_validate(pickle.loads(sample_))
|
44 |
# plaid_sample = Sample.load_from_dir(f"Tensile2d/dataset/samples/sample_"+str(sample_id_str).zfill(9))
|
45 |
|
46 |
+
nodes = plaid_sample.get_nodes(time=time)
|
47 |
+
field = plaid_sample.get_field(fieldn, time=time)
|
48 |
# if nodes.shape[1] == 2:
|
49 |
# nodes__ = np.zeros((nodes.shape[0],nodes.shape[1]+1))
|
50 |
# nodes__[:,:-1] = nodes
|
|
|
136 |
with gr.Row(variant="panel"):
|
137 |
with gr.Column(scale=1):
|
138 |
d1 = gr.Slider(0, nb_samples-1, value=0, label="Training sample id", info="Choose between 0 and "+str(nb_samples-1))
|
139 |
+
d2 = gr.Slider(0, len(times_steps)-1, value=0, label="Time step", info="Choose between 0 and "+str(len(times_steps)-1))
|
140 |
output1 = gr.Text(label="Training sample info")
|
141 |
with gr.Column(scale=2, min_width=300):
|
142 |
+
d3 = gr.Dropdown(field_names_train, value=field_names_train[0], label="Field name")
|
143 |
# output2 = gr.Image(label="Training sample visualization")
|
144 |
output2 = gr.Model3D(label="Training sample visualization")
|
145 |
|
146 |
+
d1.input(sample_info, [d1, d2, d3], [output1, output2])
|
147 |
+
d2.input(sample_info, [d1, d2, d3], [output1, output2])
|
148 |
+
d3.input(sample_info, [d1, d2, d3], [output1, output2])
|
149 |
|
150 |
demo.launch()
|
151 |
|