Yash goyal commited on
Commit
4dbaa57
·
verified ·
1 Parent(s): 56080bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -51
app.py CHANGED
@@ -152,94 +152,97 @@ def generate_pdf(report, filepath):
152
  width, height = A4
153
  y = height - 60
154
 
155
- # Clean white background
156
- c.setFillColor(colors.white)
157
  c.rect(0, 0, width, height, fill=1, stroke=0)
158
 
159
- # Subtle header background
160
- c.setFillColor(colors.Color(0.98, 0.98, 0.98, alpha=1)) # Very light gray
161
- c.rect(0, height-100, width, 100, fill=1, stroke=0)
162
 
163
- # Logo with clean styling
164
  try:
165
- if os.path.exists(LOGO_PATH):
166
- c.drawImage(LOGO_PATH, 50, y, width=60, preserveAspectRatio=True, mask='auto')
 
 
 
 
 
 
 
167
  except Exception as e:
168
  logger.warning("Logo error: %s", str(e))
169
 
170
  # Professional title
171
  c.setFont("Helvetica-Bold", 22)
172
- c.setFillColor(colors.Color(0.2, 0.2, 0.2, alpha=1)) # Dark gray
173
  c.drawCentredString(width / 2, y + 5, "Medical Diagnosis Report")
174
 
175
  # Subtitle
176
  c.setFont("Helvetica", 11)
177
- c.setFillColor(colors.Color(0.5, 0.5, 0.5, alpha=1)) # Medium gray
178
  c.drawCentredString(width / 2, y - 15, "Dermatological Analysis")
179
 
180
- # Clean separator line
181
- c.setStrokeColor(colors.Color(0.7, 0.7, 0.7, alpha=1))
182
  c.setLineWidth(1)
183
- c.line(60, y - 35, width - 60, y - 35)
184
 
185
- y -= 70
186
 
187
  def professional_section_box(title, fields, extra_gap=20):
188
  nonlocal y
189
 
190
  box_height = len(fields) * 20 + 40
191
 
192
- # Clean white background with subtle border
193
- c.setFillColor(colors.white)
194
- c.rect(50, y - box_height, width - 100, box_height, fill=1, stroke=0)
195
 
196
- # Professional border
197
- c.setStrokeColor(colors.Color(0.8, 0.8, 0.8, alpha=1))
198
- c.setLineWidth(1)
199
- c.rect(50, y - box_height, width - 100, box_height, fill=0, stroke=1)
200
 
201
- # Title bar with minimal styling
202
- c.setFillColor(colors.Color(0.95, 0.95, 0.95, alpha=1)) # Very light gray
203
- c.rect(50, y - 30, width - 100, 30, fill=1, stroke=0)
204
 
205
- # Section title
206
  c.setFont("Helvetica-Bold", 12)
207
  c.setFillColor(colors.Color(0.3, 0.3, 0.3, alpha=1))
208
- c.drawString(60, y - 20, title)
209
 
210
  y -= 45
211
  c.setFont("Helvetica", 10)
 
212
 
213
  for label, val in fields.items():
214
- # Label
215
  c.setFillColor(colors.Color(0.4, 0.4, 0.4, alpha=1))
216
- c.setFont("Helvetica-Bold", 10)
217
- c.drawString(65, y, f"{label}:")
218
-
219
- # Value
220
  c.setFillColor(colors.Color(0.2, 0.2, 0.2, alpha=1))
221
- c.setFont("Helvetica", 10)
222
- c.drawString(170, y, str(val))
223
  y -= 20
224
 
225
  y -= extra_gap
226
 
227
- # Professional sections
228
  professional_section_box("Patient Information", {
229
  "Name": report["name"],
230
  "Email": report["email"],
231
  "Gender": report["gender"],
232
- "Age": report["age"]
233
  })
234
 
235
- # Confidence indicator with professional styling
236
  confidence_val = float(report["confidence"].replace('%', ''))
237
- confidence_status = "High" if confidence_val > 85 else "Moderate" if confidence_val > 70 else "Low"
238
 
239
  professional_section_box("Diagnostic Results", {
240
  "Condition": report["prediction"],
241
- "Confidence": f"{report['confidence']} ({confidence_status})",
242
- "Notes": report["message"] if report["message"] else "None"
243
  })
244
 
245
  disease = report["prediction"]
@@ -254,21 +257,16 @@ def generate_pdf(report, filepath):
254
  })
255
 
256
  # Professional disclaimer
257
- y = 110
258
- c.setFillColor(colors.Color(0.97, 0.97, 0.97, alpha=1)) # Very light gray
259
- c.rect(50, 40, width - 100, 60, fill=1, stroke=0)
260
- c.setStrokeColor(colors.Color(0.8, 0.8, 0.8, alpha=1))
261
- c.setLineWidth(1)
262
- c.rect(50, 40, width - 100, 60, fill=0, stroke=1)
263
 
264
- # Disclaimer title
265
  c.setFont("Helvetica-Bold", 10)
266
- c.setFillColor(colors.Color(0.3, 0.3, 0.3, alpha=1))
267
- c.drawString(60, 85, "MEDICAL DISCLAIMER")
268
 
269
- # Disclaimer text
270
  c.setFont("Helvetica", 8)
271
- c.setFillColor(colors.Color(0.4, 0.4, 0.4, alpha=1))
272
  disclaimer_lines = [
273
  "This report is generated using AI technology for preliminary assessment purposes only.",
274
  "Results should not replace professional medical consultation and diagnosis.",
@@ -276,10 +274,11 @@ def generate_pdf(report, filepath):
276
  ]
277
 
278
  for i, line in enumerate(disclaimer_lines):
279
- c.drawString(60, 70 - (i * 10), line)
280
 
281
  c.save()
282
 
 
283
  @app.route("/form")
284
  def form():
285
  return render_template("form.html", history_plot="/training_plot.png")
 
152
  width, height = A4
153
  y = height - 60
154
 
155
+ # Background
156
+ c.setFillColor(colors.Color(0.98, 0.98, 0.99, alpha=1))
157
  c.rect(0, 0, width, height, fill=1, stroke=0)
158
 
159
+ # Header background
160
+ c.setFillColor(colors.Color(0.94, 0.96, 0.98, alpha=1))
161
+ c.rect(0, height-120, width, 120, fill=1, stroke=0)
162
 
163
+ # Logo from root directory
164
  try:
165
+ logo_path = "./logo.jpg" # Changed to root directory
166
+ if os.path.exists(logo_path):
167
+ # Professional logo container
168
+ c.setFillColor(colors.white)
169
+ c.circle(90, y, 30, fill=1, stroke=1)
170
+ c.setStrokeColor(colors.Color(0.7, 0.7, 0.7, alpha=1))
171
+ c.setLineWidth(1)
172
+ c.circle(90, y, 30, fill=0, stroke=1)
173
+ c.drawImage(logo_path, 65, y-20, width=50, preserveAspectRatio=True, mask='auto')
174
  except Exception as e:
175
  logger.warning("Logo error: %s", str(e))
176
 
177
  # Professional title
178
  c.setFont("Helvetica-Bold", 22)
179
+ c.setFillColor(colors.Color(0.2, 0.2, 0.2, alpha=1))
180
  c.drawCentredString(width / 2, y + 5, "Medical Diagnosis Report")
181
 
182
  # Subtitle
183
  c.setFont("Helvetica", 11)
184
+ c.setFillColor(colors.Color(0.5, 0.5, 0.5, alpha=1))
185
  c.drawCentredString(width / 2, y - 15, "Dermatological Analysis")
186
 
187
+ # Professional line
188
+ c.setStrokeColor(colors.Color(0.8, 0.8, 0.8, alpha=1))
189
  c.setLineWidth(1)
190
+ c.line(80, y - 35, width - 80, y - 35)
191
 
192
+ y -= 80
193
 
194
  def professional_section_box(title, fields, extra_gap=20):
195
  nonlocal y
196
 
197
  box_height = len(fields) * 20 + 40
198
 
199
+ # Main box with subtle shadow
200
+ c.setFillColor(colors.Color(0.96, 0.96, 0.96, alpha=0.3))
201
+ c.rect(42, y - box_height - 2, width - 84, box_height, fill=1, stroke=0)
202
 
203
+ c.setFillColor(colors.white)
204
+ c.rect(40, y - box_height, width - 80, box_height, fill=1, stroke=1)
205
+ c.setStrokeColor(colors.Color(0.9, 0.9, 0.9, alpha=1))
 
206
 
207
+ # Title bar
208
+ c.setFillColor(colors.Color(0.95, 0.95, 0.95, alpha=1))
209
+ c.rect(40, y - 30, width - 80, 30, fill=1, stroke=0)
210
 
211
+ # Title
212
  c.setFont("Helvetica-Bold", 12)
213
  c.setFillColor(colors.Color(0.3, 0.3, 0.3, alpha=1))
214
+ c.drawString(55, y - 20, title)
215
 
216
  y -= 45
217
  c.setFont("Helvetica", 10)
218
+ c.setFillColor(colors.Color(0.2, 0.2, 0.2, alpha=1))
219
 
220
  for label, val in fields.items():
221
+ c.setFont("Helvetica-Bold", 9)
222
  c.setFillColor(colors.Color(0.4, 0.4, 0.4, alpha=1))
223
+ c.drawString(55, y, f"{label}:")
224
+ c.setFont("Helvetica", 9)
 
 
225
  c.setFillColor(colors.Color(0.2, 0.2, 0.2, alpha=1))
226
+ c.drawString(150, y, str(val))
 
227
  y -= 20
228
 
229
  y -= extra_gap
230
 
231
+ # Sections
232
  professional_section_box("Patient Information", {
233
  "Name": report["name"],
234
  "Email": report["email"],
235
  "Gender": report["gender"],
236
+ "Age": f"{report['age']} years"
237
  })
238
 
 
239
  confidence_val = float(report["confidence"].replace('%', ''))
240
+ confidence_text = f"{report['confidence']} ({'High' if confidence_val > 85 else 'Moderate' if confidence_val > 70 else 'Low'} Confidence)"
241
 
242
  professional_section_box("Diagnostic Results", {
243
  "Condition": report["prediction"],
244
+ "Confidence": confidence_text,
245
+ "Notes": report["message"] if report["message"] else "No additional notes"
246
  })
247
 
248
  disease = report["prediction"]
 
257
  })
258
 
259
  # Professional disclaimer
260
+ c.setFillColor(colors.Color(0.98, 0.98, 0.98, alpha=1))
261
+ c.rect(40, 40, width - 80, 70, fill=1, stroke=1)
262
+ c.setStrokeColor(colors.Color(0.9, 0.9, 0.9, alpha=1))
 
 
 
263
 
 
264
  c.setFont("Helvetica-Bold", 10)
265
+ c.setFillColor(colors.Color(0.4, 0.4, 0.4, alpha=1))
266
+ c.drawString(50, 95, "Medical Disclaimer")
267
 
 
268
  c.setFont("Helvetica", 8)
269
+ c.setFillColor(colors.Color(0.3, 0.3, 0.3, alpha=1))
270
  disclaimer_lines = [
271
  "This report is generated using AI technology for preliminary assessment purposes only.",
272
  "Results should not replace professional medical consultation and diagnosis.",
 
274
  ]
275
 
276
  for i, line in enumerate(disclaimer_lines):
277
+ c.drawString(50, 80 - (i * 10), line)
278
 
279
  c.save()
280
 
281
+
282
  @app.route("/form")
283
  def form():
284
  return render_template("form.html", history_plot="/training_plot.png")