Update app.py
Browse files
app.py
CHANGED
@@ -35,14 +35,16 @@ def generate_report(name, age, gender, weight, height, allergies, cause, xray):
|
|
35 |
|
36 |
# Injury severity classification
|
37 |
severity = "Mild" if prediction < 0.3 else "Moderate" if prediction < 0.7 else "Severe"
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
"
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
46 |
cost_duration_data = [
|
47 |
["Hospital Type", "Estimated Cost", "Recovery Time"],
|
48 |
["Government Hospital", f"₹{2000 if severity == 'Mild' else 8000 if severity == 'Moderate' else 20000} - ₹{5000 if severity == 'Mild' else 15000 if severity == 'Moderate' else 50000}", "4-12 weeks"],
|
@@ -57,12 +59,13 @@ def generate_report(name, age, gender, weight, height, allergies, cause, xray):
|
|
57 |
# Generate PDF report
|
58 |
report_path = f"{name}_fracture_report.pdf"
|
59 |
c = canvas.Canvas(report_path, pagesize=letter)
|
60 |
-
|
|
|
|
|
61 |
c.drawString(200, 770, "Bone Fracture Detection Report")
|
62 |
|
63 |
# Patient details table
|
64 |
patient_data = [
|
65 |
-
["Attribute", "Details"],
|
66 |
["Patient Name", name],
|
67 |
["Age", age],
|
68 |
["Gender", gender],
|
@@ -74,42 +77,38 @@ def generate_report(name, age, gender, weight, height, allergies, cause, xray):
|
|
74 |
["Injury Severity", severity]
|
75 |
]
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
(
|
80 |
-
(
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
# Load and insert X-ray image
|
90 |
c.drawInlineImage(img_path, 50, 320, width=250, height=250)
|
91 |
c.setFont("Helvetica-Bold", 12)
|
92 |
c.drawString(120, 290, f"Fractured: {'Yes' if diagnosed_class == 'Fractured' else 'No'}")
|
93 |
|
94 |
-
#
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
('GRID', (0, 0), (-1, -1), 1, colors.black)
|
103 |
-
]))
|
104 |
-
cost_table.wrapOn(c, 400, 200)
|
105 |
-
cost_table.drawOn(c, 50, 120)
|
106 |
-
|
107 |
-
# Add Treatment Recommendations
|
108 |
-
c.setFont("Helvetica-Bold", 12)
|
109 |
-
c.drawString(50, 100, "Treatment & Recovery Recommendations:")
|
110 |
-
c.setFont("Helvetica", 10)
|
111 |
-
c.drawString(50, 80, treatment)
|
112 |
-
c.drawString(50, 60, "Follow proper medical care and consult your doctor regularly.")
|
113 |
|
114 |
c.save()
|
115 |
|
|
|
35 |
|
36 |
# Injury severity classification
|
37 |
severity = "Mild" if prediction < 0.3 else "Moderate" if prediction < 0.7 else "Severe"
|
38 |
+
|
39 |
+
# Treatment details table
|
40 |
+
treatment_data = [
|
41 |
+
["Severity Level", "Recommended Treatment", "Recovery Duration"],
|
42 |
+
["Mild", "Rest, pain relievers, and follow-up X-ray", "4-6 weeks"],
|
43 |
+
["Moderate", "Plaster cast, minor surgery if needed", "6-10 weeks"],
|
44 |
+
["Severe", "Major surgery, metal implants, physiotherapy", "Several months"]
|
45 |
+
]
|
46 |
+
|
47 |
+
# Estimated cost & duration table
|
48 |
cost_duration_data = [
|
49 |
["Hospital Type", "Estimated Cost", "Recovery Time"],
|
50 |
["Government Hospital", f"₹{2000 if severity == 'Mild' else 8000 if severity == 'Moderate' else 20000} - ₹{5000 if severity == 'Mild' else 15000 if severity == 'Moderate' else 50000}", "4-12 weeks"],
|
|
|
59 |
# Generate PDF report
|
60 |
report_path = f"{name}_fracture_report.pdf"
|
61 |
c = canvas.Canvas(report_path, pagesize=letter)
|
62 |
+
|
63 |
+
# Report title
|
64 |
+
c.setFont("Helvetica-Bold", 16)
|
65 |
c.drawString(200, 770, "Bone Fracture Detection Report")
|
66 |
|
67 |
# Patient details table
|
68 |
patient_data = [
|
|
|
69 |
["Patient Name", name],
|
70 |
["Age", age],
|
71 |
["Gender", gender],
|
|
|
77 |
["Injury Severity", severity]
|
78 |
]
|
79 |
|
80 |
+
# Format and align tables
|
81 |
+
def format_table(data):
|
82 |
+
table = Table(data, colWidths=[270, 270]) # Set 90% width
|
83 |
+
table.setStyle(TableStyle([
|
84 |
+
('BACKGROUND', (0, 0), (-1, 0), colors.darkblue),
|
85 |
+
('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),
|
86 |
+
('ALIGN', (0, 0), (-1, -1), 'CENTER'),
|
87 |
+
('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
|
88 |
+
('BOTTOMPADDING', (0, 0), (-1, 0), 12),
|
89 |
+
('GRID', (0, 0), (-1, -1), 1, colors.black),
|
90 |
+
('VALIGN', (0, 0), (-1, -1), 'MIDDLE')
|
91 |
+
]))
|
92 |
+
return table
|
93 |
+
|
94 |
+
# Draw patient details table
|
95 |
+
patient_table = format_table(patient_data)
|
96 |
+
patient_table.wrapOn(c, 480, 500)
|
97 |
+
patient_table.drawOn(c, 50, 620)
|
98 |
|
99 |
# Load and insert X-ray image
|
100 |
c.drawInlineImage(img_path, 50, 320, width=250, height=250)
|
101 |
c.setFont("Helvetica-Bold", 12)
|
102 |
c.drawString(120, 290, f"Fractured: {'Yes' if diagnosed_class == 'Fractured' else 'No'}")
|
103 |
|
104 |
+
# Draw treatment and cost tables
|
105 |
+
treatment_table = format_table(treatment_data)
|
106 |
+
treatment_table.wrapOn(c, 480, 200)
|
107 |
+
treatment_table.drawOn(c, 50, 200)
|
108 |
+
|
109 |
+
cost_table = format_table(cost_duration_data)
|
110 |
+
cost_table.wrapOn(c, 480, 150)
|
111 |
+
cost_table.drawOn(c, 50, 80)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
c.save()
|
114 |
|