rnmee commited on
Commit
3eaadc1
·
verified ·
1 Parent(s): 7d2f2cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -237,16 +237,16 @@ def generate_pdf_report(original_img: Image.Image, mask: np.ndarray, overlay: Im
237
  pdf.set_font("helvetica", "I", 10)
238
  pdf.cell(text="This report was generated by DR Analysis System", new_x="LMARGIN", new_y="NEXT", align='C')
239
 
240
- # Get PDF as bytes
241
- pdf_output = pdf.output()
242
- if isinstance(pdf_output, str):
243
- return pdf_output.encode('latin1')
244
- return pdf_output
245
 
246
  except Exception as e:
247
  st.error(f"PDF generation failed: {str(e)}")
248
  return None
249
 
 
 
250
  # ====================== MAIN APP ======================
251
  def main():
252
  st.set_page_config(layout="wide")
@@ -325,6 +325,7 @@ def main():
325
  "image/png"
326
  )
327
 
 
328
  with col2:
329
  # Generate and download PDF report
330
  pdf_bytes = generate_pdf_report(
@@ -336,12 +337,15 @@ def main():
336
  seg_results['bright_area'],
337
  seg_results['red_area']
338
  )
339
- st.download_button(
340
- "Download Full Report",
341
- data=pdf_bytes,
342
- file_name="dr_diagnosis_report.pdf",
343
- mime="application/pdf"
344
- )
 
 
 
345
 
346
  except Exception as e:
347
  st.error(f"Error processing image: {str(e)}")
 
237
  pdf.set_font("helvetica", "I", 10)
238
  pdf.cell(text="This report was generated by DR Analysis System", new_x="LMARGIN", new_y="NEXT", align='C')
239
 
240
+ # Get PDF as bytes - this is the critical fix
241
+ pdf_bytes = pdf.output(dest='S').encode('latin1')
242
+ return pdf_bytes
 
 
243
 
244
  except Exception as e:
245
  st.error(f"PDF generation failed: {str(e)}")
246
  return None
247
 
248
+
249
+
250
  # ====================== MAIN APP ======================
251
  def main():
252
  st.set_page_config(layout="wide")
 
325
  "image/png"
326
  )
327
 
328
+ # In your main app where you create the download button:
329
  with col2:
330
  # Generate and download PDF report
331
  pdf_bytes = generate_pdf_report(
 
337
  seg_results['bright_area'],
338
  seg_results['red_area']
339
  )
340
+ if pdf_bytes is not None:
341
+ st.download_button(
342
+ "Download Full Report",
343
+ data=pdf_bytes,
344
+ file_name="dr_diagnosis_report.pdf",
345
+ mime="application/pdf"
346
+ )
347
+ else:
348
+ st.warning("Failed to generate PDF report")
349
 
350
  except Exception as e:
351
  st.error(f"Error processing image: {str(e)}")