TANVEERMAKHDOOM commited on
Commit
ef12e47
Β·
verified Β·
1 Parent(s): d6953c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -6
app.py CHANGED
@@ -1,9 +1,10 @@
1
  import streamlit as st
 
2
 
3
  # Set page config
4
  st.set_page_config(page_title="BMI Calculator", page_icon="βš–οΈ", layout="centered")
5
 
6
- # Apply custom CSS for fonts and style
7
  st.markdown("""
8
  <style>
9
  .main {
@@ -30,8 +31,17 @@ st.markdown("---")
30
  with st.container():
31
  st.markdown("<div class='card'>", unsafe_allow_html=True)
32
 
33
- # Inputs
34
- st.subheader("Enter your details:")
 
 
 
 
 
 
 
 
 
35
 
36
  weight = st.number_input("Weight (in kilograms):", min_value=1.0, format="%.2f")
37
 
@@ -42,7 +52,6 @@ with st.container():
42
  with col2:
43
  inches = st.number_input("Inches:", min_value=0, format="%i")
44
 
45
- # Calculate BMI live
46
  def calculate_bmi(weight, feet, inches):
47
  total_inches = (feet * 12) + inches
48
  height_meters = total_inches * 0.0254
@@ -57,17 +66,57 @@ with st.container():
57
  st.markdown("---")
58
  st.subheader("Result:")
59
 
60
- # Show result with different colors
61
  if bmi < 18.5:
62
  st.success(f"Your BMI is {bmi} β€” Underweight.")
 
63
  elif 18.5 <= bmi < 24.9:
64
  st.success(f"Your BMI is {bmi} β€” Normal weight. πŸ‘")
 
65
  elif 25 <= bmi < 29.9:
66
  st.warning(f"Your BMI is {bmi} β€” Overweight.")
 
67
  else:
68
  st.error(f"Your BMI is {bmi} β€” Obese.")
69
-
70
  else:
71
  st.info("Please enter your height and weight.")
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  st.markdown("</div>", unsafe_allow_html=True)
 
1
  import streamlit as st
2
+ from fpdf import FPDF
3
 
4
  # Set page config
5
  st.set_page_config(page_title="BMI Calculator", page_icon="βš–οΈ", layout="centered")
6
 
7
+ # Apply custom CSS
8
  st.markdown("""
9
  <style>
10
  .main {
 
31
  with st.container():
32
  st.markdown("<div class='card'>", unsafe_allow_html=True)
33
 
34
+ # Patient Information
35
+ st.subheader("Patient Information")
36
+ patient_name = st.text_input("Name of Patient:")
37
+ patient_age = st.number_input("Age:", min_value=0, max_value=120, step=1)
38
+ patient_gender = st.selectbox("Gender:", ["Select", "Male", "Female", "Other"])
39
+ patient_notes = st.text_area("Additional Notes:")
40
+
41
+ st.markdown("---")
42
+
43
+ # BMI Calculation Section
44
+ st.subheader("Body Measurements")
45
 
46
  weight = st.number_input("Weight (in kilograms):", min_value=1.0, format="%.2f")
47
 
 
52
  with col2:
53
  inches = st.number_input("Inches:", min_value=0, format="%i")
54
 
 
55
  def calculate_bmi(weight, feet, inches):
56
  total_inches = (feet * 12) + inches
57
  height_meters = total_inches * 0.0254
 
66
  st.markdown("---")
67
  st.subheader("Result:")
68
 
69
+ bmi_status = ""
70
  if bmi < 18.5:
71
  st.success(f"Your BMI is {bmi} β€” Underweight.")
72
+ bmi_status = "Underweight"
73
  elif 18.5 <= bmi < 24.9:
74
  st.success(f"Your BMI is {bmi} β€” Normal weight. πŸ‘")
75
+ bmi_status = "Normal weight"
76
  elif 25 <= bmi < 29.9:
77
  st.warning(f"Your BMI is {bmi} β€” Overweight.")
78
+ bmi_status = "Overweight"
79
  else:
80
  st.error(f"Your BMI is {bmi} β€” Obese.")
81
+ bmi_status = "Obese"
82
  else:
83
  st.info("Please enter your height and weight.")
84
 
85
+ st.markdown("---")
86
+
87
+ # Function to generate PDF
88
+ def create_pdf(name, age, gender, notes, bmi_value, bmi_status):
89
+ pdf = FPDF()
90
+ pdf.add_page()
91
+ pdf.set_font("Arial", 'B', 16)
92
+ pdf.cell(0, 10, "BMI Report", ln=True, align="C")
93
+ pdf.ln(10)
94
+
95
+ pdf.set_font("Arial", '', 12)
96
+ pdf.cell(0, 10, f"Patient Name: {name}", ln=True)
97
+ pdf.cell(0, 10, f"Age: {age}", ln=True)
98
+ pdf.cell(0, 10, f"Gender: {gender}", ln=True)
99
+ pdf.cell(0, 10, f"BMI: {bmi_value} ({bmi_status})", ln=True)
100
+ pdf.ln(5)
101
+ pdf.multi_cell(0, 10, f"Notes: {notes}")
102
+
103
+ return pdf
104
+
105
+ # Only show download if BMI is calculated
106
+ if bmi and patient_name:
107
+ pdf = create_pdf(patient_name, patient_age, patient_gender, patient_notes, bmi, bmi_status)
108
+
109
+ # Save PDF temporarily in memory
110
+ import io
111
+ pdf_buffer = io.BytesIO()
112
+ pdf.output(pdf_buffer)
113
+ pdf_buffer.seek(0)
114
+
115
+ st.download_button(
116
+ label="πŸ“„ Download BMI Report as PDF",
117
+ data=pdf_buffer,
118
+ file_name=f"{patient_name}_BMI_Report.pdf",
119
+ mime="application/pdf"
120
+ )
121
+
122
  st.markdown("</div>", unsafe_allow_html=True)