Spaces:
Runtime error
Runtime error
File size: 3,071 Bytes
2b3114a |
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 92 93 94 95 96 97 98 |
import plotly.graph_objects as go
def Intelligibility_Plot(Int_Score, fair_thre=30, good_thre = 70, Upper=100, Lower=0):
'''
Int_Score: a float number between 0 and 100
Upper: the upper bound of the plot
Lower: the lower bound of the plot
'''
# Assert Nat_Score is a float number between 0 and 100
assert isinstance(Int_Score, float|int)
assert Int_Score >= Lower
assert Int_Score <= Upper
# Indicator plot with different colors, under fair_threshold the plot is red, then yellow, then green
# Design 1: Show bar in different colors refer to the threshold
color = "#75DA99"
if Int_Score <= fair_thre:
color = "#F2ADA0"
elif Int_Score <= good_thre:
color = "#e8ee89"
else:
color = "#75DA99"
fig = go.Figure(go.Indicator(
mode="number+gauge",
gauge={'shape': "bullet",
'axis':{'range': [Lower, Upper]},
'bgcolor': 'white',
'bar': {'color': color},
},
value=Int_Score,
domain = {'x': [0, 1], 'y': [0, 1]},
)
)
# # Design 2: Show all thresholds in the background
# fig = go.Figure(go.Indicator(
# mode = "number+gauge",
# gauge = {'shape': "bullet",
# 'axis': {'range': [Lower, Upper]},
# 'bgcolor': 'white',
# 'steps': [
# {'range': [Lower, fair_thre], 'color': "#F2ADA0"},
# {'range': [fair_thre, good_thre], 'color': "#e8ee89"},
# {'range': [good_thre, Upper], 'color': " #75DA99"}],
# 'bar': {'color': "grey"},
# },
# value = Int_Score,
# domain = {'x': [0, 1], 'y': [0, 1]},
# )
# )
fig.update_layout(height=300, width=1000)
return fig
def Naturalness_Plot(Nat_Score, fair_thre=2, good_thre = 4, Upper=5, Lower=1.0):
'''
Int_Score: a float number between 0 and 100
Upper: the upper bound of the plot
Lower: the lower bound of the plot
'''
# Assert Nat_Score is a float number between 0 and 100
assert isinstance(Nat_Score, float|int)
assert Nat_Score >= Lower
assert Nat_Score <= Upper
# Indicator plot with different colors, under fair_threshold the plot is red, then yellow, then green
color = "#75DA99"
if Nat_Score <= fair_thre:
color = "#F2ADA0"
elif Nat_Score <= good_thre:
color = "#e8ee89"
else:
color = "#75DA99"
fig = go.Figure(go.Indicator(
mode="number+gauge",
gauge={'shape': "bullet",
'axis':{'range': [Lower, Upper]},
'bgcolor': 'white',
'bar': {'color': color},
},
value=Nat_Score,
domain = {'x': [0, 1], 'y': [0, 1]},
)
)
fig.update_layout(height=300, width=1000)
return fig
# test case Intelligibility_Plot
x = Intelligibility_Plot(10)
x.show()
x = Intelligibility_Plot(50)
x.show()
x = Intelligibility_Plot(90)
x.show()
|