Spaces:
Sleeping
Sleeping
marta-marta
commited on
Commit
·
5c52661
1
Parent(s):
470fd34
Should be fully functional :D
Browse files
app.py
CHANGED
@@ -244,6 +244,13 @@ def combine_arrays(arrays):
|
|
244 |
return output_array
|
245 |
|
246 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
########################################################################################################################
|
248 |
# Provide the Options for users to select from
|
249 |
shape_options = ("basic_box", "diagonal_box_split", "horizontal_vertical_box_split", "back_slash_box", "forward_slash_box",
|
@@ -254,20 +261,21 @@ thickness_options = [str(int(x)) for x in np.linspace(0, 10, 11)]
|
|
254 |
interpolation_options = [str(int(x)) for x in [3, 5, 10, 20]]
|
255 |
|
256 |
# Provide User Options
|
|
|
257 |
# Select Shapes
|
258 |
shape_1 = st.selectbox("Shape 1", shape_options)
|
259 |
shape_2 = st.selectbox("Shape 2", shape_options)
|
260 |
|
261 |
# Select Density
|
262 |
-
density_1 = st.selectbox("Density 1:", density_options)
|
263 |
-
density_2 = st.selectbox("Density 2:", density_options)
|
264 |
|
265 |
# Select Thickness
|
266 |
thickness_1 = st.selectbox("Thickness 1", thickness_options)
|
267 |
thickness_2 = st.selectbox("Thickness 2", thickness_options)
|
268 |
|
269 |
# Select Interpolation Length
|
270 |
-
interp_length = st.selectbox("Interpolation Length", interpolation_options)
|
271 |
|
272 |
|
273 |
# Define the function to generate unit cells based on user inputs
|
@@ -318,47 +326,68 @@ for column in range(latent_dimensionality):
|
|
318 |
latent_matrix = np.array(latent_matrix).T # Transposes the matrix so that each row can be easily indexed
|
319 |
########################################################################################################################
|
320 |
# Plotting the Interpolation in 2D Using Chosen Points
|
321 |
-
if st.button("Generate Interpolation"):
|
322 |
-
plt.figure(2)
|
323 |
|
324 |
linear_interp_latent = np.linspace(latent_point_1, latent_point_2, num_interp)
|
325 |
print(len(linear_interp_latent))
|
326 |
|
327 |
linear_predicted_interps = []
|
328 |
-
|
329 |
for i in range(num_interp):
|
330 |
generated_image = decoder_model_boxes.predict(np.array([linear_interp_latent[i]]))[0]
|
331 |
-
|
332 |
linear_predicted_interps.append(generated_image[:, :, -1])
|
333 |
|
334 |
-
plt.
|
335 |
# plt.imshow(figure, cmap='gray')
|
336 |
-
plt.figure(2)
|
337 |
-
st.pyplot(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
338 |
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
plt.subplot(
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
362 |
latent_matrix_2 = [] # This will contain the latent points of the interpolation
|
363 |
for column in range(latent_dimensionality):
|
364 |
new_column = np.linspace(latent_point_3[column], latent_point_4[column], num_interp)
|
@@ -373,15 +402,13 @@ if st.button("Generate Interpolation"):
|
|
373 |
mesh = np.transpose(mesh, axes=(1, 0, 2)) # Transpose the array so it matches the original interpolation
|
374 |
generator_model = decoder_model_boxes
|
375 |
|
376 |
-
|
377 |
|
378 |
mesh_predicted_interps = []
|
379 |
for i in range(num_interp):
|
380 |
for j in range(num_interp):
|
381 |
generated_image = generator_model.predict(np.array([mesh[i][j]]))[0]
|
382 |
-
|
383 |
mesh_predicted_interps.append(generated_image[:, :, -1])
|
384 |
|
385 |
-
|
386 |
-
plt.imshow(figure, cmap='gray')
|
387 |
-
'''
|
|
|
244 |
return output_array
|
245 |
|
246 |
|
247 |
+
########################################################################################################################
|
248 |
+
# Explain the App
|
249 |
+
st.header("Multi-Lattice Generator Through a VAE Model")
|
250 |
+
st.write("Shape: the type of shape the lattice will have")
|
251 |
+
st.write("Density: the pixel intensity of each activated pixel")
|
252 |
+
st.write("Thickness: the additional pixels added to the base shape")
|
253 |
+
st.write("Interpolation Length: the number of internal interpolation points that will exist in the interpolation")
|
254 |
########################################################################################################################
|
255 |
# Provide the Options for users to select from
|
256 |
shape_options = ("basic_box", "diagonal_box_split", "horizontal_vertical_box_split", "back_slash_box", "forward_slash_box",
|
|
|
261 |
interpolation_options = [str(int(x)) for x in [3, 5, 10, 20]]
|
262 |
|
263 |
# Provide User Options
|
264 |
+
st.header("Option 1: Perform a Linear Interpolation")
|
265 |
# Select Shapes
|
266 |
shape_1 = st.selectbox("Shape 1", shape_options)
|
267 |
shape_2 = st.selectbox("Shape 2", shape_options)
|
268 |
|
269 |
# Select Density
|
270 |
+
density_1 = st.selectbox("Density 1:", density_options, index=len(density_options)-1)
|
271 |
+
density_2 = st.selectbox("Density 2:", density_options, index=len(density_options)-1)
|
272 |
|
273 |
# Select Thickness
|
274 |
thickness_1 = st.selectbox("Thickness 1", thickness_options)
|
275 |
thickness_2 = st.selectbox("Thickness 2", thickness_options)
|
276 |
|
277 |
# Select Interpolation Length
|
278 |
+
interp_length = st.selectbox("Interpolation Length", interpolation_options, index=2)
|
279 |
|
280 |
|
281 |
# Define the function to generate unit cells based on user inputs
|
|
|
326 |
latent_matrix = np.array(latent_matrix).T # Transposes the matrix so that each row can be easily indexed
|
327 |
########################################################################################################################
|
328 |
# Plotting the Interpolation in 2D Using Chosen Points
|
329 |
+
if st.button("Generate Linear Interpolation"):
|
330 |
+
# plt.figure(2)
|
331 |
|
332 |
linear_interp_latent = np.linspace(latent_point_1, latent_point_2, num_interp)
|
333 |
print(len(linear_interp_latent))
|
334 |
|
335 |
linear_predicted_interps = []
|
336 |
+
figure_2 = np.zeros((28, 28 * num_interp))
|
337 |
for i in range(num_interp):
|
338 |
generated_image = decoder_model_boxes.predict(np.array([linear_interp_latent[i]]))[0]
|
339 |
+
figure_2[0:28, i * 28:(i + 1) * 28, ] = generated_image[:, :, -1]
|
340 |
linear_predicted_interps.append(generated_image[:, :, -1])
|
341 |
|
342 |
+
# plt.figure_2(figsize=(15, 15))
|
343 |
# plt.imshow(figure, cmap='gray')
|
344 |
+
# plt.figure(2)
|
345 |
+
# st.pyplot(figure_2)
|
346 |
+
st.image(figure_2)
|
347 |
+
########################################################################################################################
|
348 |
+
# Provide User Options
|
349 |
+
st.header("Option 2: Perform a Mesh Interpolation")
|
350 |
+
st.write("The four corners of this mesh are defined using the shapes in both Option 1 and Option 2")
|
351 |
+
# Select Shapes
|
352 |
+
shape_3 = st.selectbox("Shape 3", shape_options)
|
353 |
+
shape_4 = st.selectbox("Shape 4", shape_options)
|
354 |
|
355 |
+
# Select Density
|
356 |
+
density_3 = st.selectbox("Density 3:", density_options, index=len(density_options)-1)
|
357 |
+
density_4 = st.selectbox("Density 4:", density_options, index=len(density_options)-1)
|
358 |
+
|
359 |
+
# Select Thickness
|
360 |
+
thickness_3 = st.selectbox("Thickness 3", thickness_options)
|
361 |
+
thickness_4 = st.selectbox("Thickness 4", thickness_options)
|
362 |
+
|
363 |
+
# Generate the endpoints
|
364 |
+
number_3 = generate_unit_cell(shape_3, density_3, thickness_3)
|
365 |
+
number_4 = generate_unit_cell(shape_4, density_4, thickness_4)
|
366 |
+
|
367 |
+
# Display the endpoints to the user
|
368 |
+
if st.button("Generate Endpoint Images for Mesh"):
|
369 |
+
plt.figure(1)
|
370 |
+
st.header("Endpoints to be generated:")
|
371 |
+
plt.subplot(2, 2, 1), plt.imshow(number_1, cmap='gray', vmin=0, vmax=1)
|
372 |
+
plt.subplot(2, 2, 2), plt.imshow(number_2, cmap='gray', vmin=0, vmax=1)
|
373 |
+
plt.subplot(2, 2, 3), plt.imshow(number_3, cmap='gray', vmin=0, vmax=1)
|
374 |
+
plt.subplot(2, 2, 4), plt.imshow(number_4, cmap='gray', vmin=0, vmax=1)
|
375 |
+
plt.figure(1)
|
376 |
+
st.pyplot(plt.figure(1))
|
377 |
+
########################################################################################################################
|
378 |
+
# Encode the Desired Endpoints
|
379 |
+
# resize the array to match the prediction size requirement
|
380 |
+
number_3_expand = np.expand_dims(np.expand_dims(number_3, axis=2), axis=0)
|
381 |
+
number_4_expand = np.expand_dims(np.expand_dims(number_4, axis=2), axis=0)
|
382 |
+
|
383 |
+
# Determine the latent point that will represent our desired number
|
384 |
+
latent_point_3 = encoder_model_boxes.predict(number_3_expand)[0]
|
385 |
+
latent_point_4 = encoder_model_boxes.predict(number_4_expand)[0]
|
386 |
+
|
387 |
+
latent_dimensionality = len(latent_point_1) # define the dimensionality of the latent space
|
388 |
+
########################################################################################################################
|
389 |
+
# Plot a Mesh Gridded Interpolation
|
390 |
+
if st.button("Generate Mesh Interpolation"):
|
391 |
latent_matrix_2 = [] # This will contain the latent points of the interpolation
|
392 |
for column in range(latent_dimensionality):
|
393 |
new_column = np.linspace(latent_point_3[column], latent_point_4[column], num_interp)
|
|
|
402 |
mesh = np.transpose(mesh, axes=(1, 0, 2)) # Transpose the array so it matches the original interpolation
|
403 |
generator_model = decoder_model_boxes
|
404 |
|
405 |
+
figure_3 = np.zeros((28 * num_interp, 28 * num_interp))
|
406 |
|
407 |
mesh_predicted_interps = []
|
408 |
for i in range(num_interp):
|
409 |
for j in range(num_interp):
|
410 |
generated_image = generator_model.predict(np.array([mesh[i][j]]))[0]
|
411 |
+
figure_3[i * 28:(i + 1) * 28, j * 28:(j + 1) * 28, ] = generated_image[:, :, -1]
|
412 |
mesh_predicted_interps.append(generated_image[:, :, -1])
|
413 |
|
414 |
+
st.image(figure_3)
|
|
|
|