Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -31,18 +31,28 @@ shapes = {
|
|
31 |
"rectangle": rectangle,
|
32 |
}
|
33 |
|
|
|
|
|
34 |
def randomize(selection):
|
35 |
index = random.randint(0, 9)
|
36 |
mask = 255*numpy.array(json.loads(shapes[selection]['Defects'][index]))
|
37 |
v = numpy.array(json.loads(shapes[selection]['Strain'][index]))
|
38 |
-
print(v)
|
39 |
# Get the color map by name:
|
40 |
cm = matplotlib.pyplot.get_cmap('RdBu')
|
41 |
measure = max(v.max(), -v.min())
|
42 |
-
print(measure)
|
43 |
output = (v / measure)
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
with gradio.Blocks() as demo:
|
48 |
selection = gradio.Dropdown(["circle", "crescent", "ellipse", "peanut", "triangle", "rectangle"], label="Select defect shape")
|
@@ -56,5 +66,6 @@ with gradio.Blocks() as demo:
|
|
56 |
eyy = gradio.Image(label="ε-yy")
|
57 |
with gradio.Column():
|
58 |
exy = gradio.Image(label="ε-xy")
|
|
|
59 |
selection.change(fn=randomize, inputs=[selection], outputs=[mask, exx, eyy, exy])
|
60 |
demo.launch(debug=True)
|
|
|
31 |
"rectangle": rectangle,
|
32 |
}
|
33 |
|
34 |
+
|
35 |
+
|
36 |
def randomize(selection):
|
37 |
index = random.randint(0, 9)
|
38 |
mask = 255*numpy.array(json.loads(shapes[selection]['Defects'][index]))
|
39 |
v = numpy.array(json.loads(shapes[selection]['Strain'][index]))
|
|
|
40 |
# Get the color map by name:
|
41 |
cm = matplotlib.pyplot.get_cmap('RdBu')
|
42 |
measure = max(v.max(), -v.min())
|
|
|
43 |
output = (v / measure)
|
44 |
+
|
45 |
+
legend = "<h2>Strain</h2><table style=\"width:100%\"><tr>"
|
46 |
+
for i in range(11):
|
47 |
+
color = cm(i/10.0)[:3]
|
48 |
+
value = -measure + i*2*measure/10
|
49 |
+
print(sum(list(color)))
|
50 |
+
hex = matplotlib.colors.to_hex(list(color))
|
51 |
+
text_color = "black" if sum(list(color)) > 2.0 else "white"
|
52 |
+
legend = legend + f"<td style=\"background-color: {hex}; color: {text_color}\">{value:+.2e}</td>"
|
53 |
+
legend = legend + "</tr></table>"
|
54 |
+
|
55 |
+
return mask, cm((numpy.multiply(output[:, :, 0], mask/255.0)+1.0)/2.0), cm((numpy.multiply(output[:, :, 1], mask/255.0)+1.0)/2.0), cm((numpy.multiply(output[:, :, 2], mask/255.0)+1.0)/2.0), legend
|
56 |
|
57 |
with gradio.Blocks() as demo:
|
58 |
selection = gradio.Dropdown(["circle", "crescent", "ellipse", "peanut", "triangle", "rectangle"], label="Select defect shape")
|
|
|
66 |
eyy = gradio.Image(label="ε-yy")
|
67 |
with gradio.Column():
|
68 |
exy = gradio.Image(label="ε-xy")
|
69 |
+
gradio.HTML(label="", value="")
|
70 |
selection.change(fn=randomize, inputs=[selection], outputs=[mask, exx, eyy, exy])
|
71 |
demo.launch(debug=True)
|