Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
-
import numpy
|
2 |
-
import keras
|
3 |
-
import gradio
|
4 |
-
import matplotlib.pyplot
|
5 |
-
import matplotlib.colors
|
6 |
|
7 |
# Building the neural network
|
8 |
model1 = keras.models.Sequential()
|
@@ -40,6 +40,7 @@ def scale(im, nR, nC):
|
|
40 |
for c in range(nC)] for r in range(nR)])
|
41 |
|
42 |
|
|
|
43 |
def predict(mask):
|
44 |
scaled_mask = numpy.ones((101, 636)) if mask is None else numpy.round(scale(mask, 101, 636)/255.0)
|
45 |
print(scaled_mask)
|
@@ -72,7 +73,6 @@ with gradio.Blocks() as demo:
|
|
72 |
gradio.Markdown("It can be challenging to rapidly infer the stress and strain that are present in a material with a complex microstructure. This demo runs a rapid surrogate model to compute strain for the microstructure that you draw!")
|
73 |
|
74 |
mask = gradio.Image(image_mode="L", source="canvas", label="microstructure")
|
75 |
-
mask.update(fn=predict, inputs=[mask], outputs=[exx, eyy, exy, legend])
|
76 |
|
77 |
btn = gradio.Button("Run!", variant="primary")
|
78 |
exx = gradio.Image(label="ε-xx")
|
|
|
1 |
+
import numpy # for miscellaneous
|
2 |
+
import keras # for network
|
3 |
+
import gradio # for interface
|
4 |
+
import matplotlib.pyplot # for colormap
|
5 |
+
import matplotlib.colors # for color conversion
|
6 |
|
7 |
# Building the neural network
|
8 |
model1 = keras.models.Sequential()
|
|
|
40 |
for c in range(nC)] for r in range(nR)])
|
41 |
|
42 |
|
43 |
+
# Prediction function
|
44 |
def predict(mask):
|
45 |
scaled_mask = numpy.ones((101, 636)) if mask is None else numpy.round(scale(mask, 101, 636)/255.0)
|
46 |
print(scaled_mask)
|
|
|
73 |
gradio.Markdown("It can be challenging to rapidly infer the stress and strain that are present in a material with a complex microstructure. This demo runs a rapid surrogate model to compute strain for the microstructure that you draw!")
|
74 |
|
75 |
mask = gradio.Image(image_mode="L", source="canvas", label="microstructure")
|
|
|
76 |
|
77 |
btn = gradio.Button("Run!", variant="primary")
|
78 |
exx = gradio.Image(label="ε-xx")
|