File size: 1,737 Bytes
41cef72 |
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 |
import streamlit as st
import plotly.graph_objs as go
def BMI_Value(height,weight):
height = height/100
bmi = weight / (height ** 2)
color = "black"
if bmi <= 18.5:
bmi_class = 'Thin'
color = "blue"
elif bmi < 24.0:
bmi_class = 'Ideal'
color = "green"
elif bmi < 28.0:
bmi_class = 'Fat'
color = "yellow"
else:
bmi_class = 'Obesity'
color = "red"
fig = go.Figure(go.Indicator(
mode = "gauge+number",
value = bmi,
domain = {'x': [0, 1], 'y': [0, 1]},
title = {'text': "BMI"},
number = {'font': {'color': color},'suffix': f"<br>({bmi_class})"}, # Change number color based on value
gauge = {'axis': {'range': [None, 60]},
'bar': {'color': "white",'thickness': 0},
'steps' : [
{'range': [0, 18.5], 'color': "blue"},
{'range': [18.5, 24.0], 'color': "green"},
{'range': [24.0, 28.0], 'color': "yellow"},
{'range': [28.0, 60], 'color': "red"}],
'threshold' : {'line': {'color': "black", 'width': 7}, 'thickness': 1, 'value': bmi}}))
fig.add_trace(go.Scatter(
x=[0],
y=[0],
#marker=dict(color="red", size=12),
showlegend=False,
name="BMI",
))
fig.update_layout(width=400, height=300, plot_bgcolor='rgba(0,0,0,0)', showlegend=False, xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False))
fig.update_traces(x=[bmi], selector=dict(name="BMI"))
return fig
if __name__ == "__main__":
BMI_Value() |