rnmee commited on
Commit
7d2f2cf
·
verified ·
1 Parent(s): 93bb1b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -18
app.py CHANGED
@@ -91,7 +91,7 @@ class UNet(nn.Module):
91
 
92
  # ====================== CLASSIFIER ======================
93
  def create_classifier_model():
94
- model = models.resnet152(pretrained=False)
95
  num_ftrs = model.fc.in_features
96
  model.fc = nn.Sequential(
97
  nn.Linear(num_ftrs, 512),
@@ -188,32 +188,32 @@ def generate_pdf_report(original_img: Image.Image, mask: np.ndarray, overlay: Im
188
  pdf = FPDF()
189
  pdf.add_page()
190
 
191
- # Modern FPDF2 syntax
192
  pdf.set_font("helvetica", "B", 16)
193
- pdf.cell(txt="Diabetic Retinopathy Diagnosis Report", new_x="LMARGIN", new_y="NEXT", align='C')
194
  pdf.ln(10)
195
 
196
  # Patient Info
197
  pdf.set_font("helvetica", "", 12)
198
- pdf.cell(txt="Patient: ___________________________", new_x="LMARGIN", new_y="NEXT")
199
- pdf.cell(txt="Date: _____________________________", new_x="LMARGIN", new_y="NEXT")
200
  pdf.ln(10)
201
 
202
  # Diagnosis
203
  pdf.set_font("helvetica", "B", 14)
204
- pdf.cell(txt="Diagnosis:", new_x="LMARGIN", new_y="NEXT")
205
  pdf.set_font("helvetica", "", 12)
206
- pdf.cell(txt=f"Stage: {diagnosis}", new_x="LMARGIN", new_y="NEXT")
207
- pdf.cell(txt=f"Grading: {grade}", new_x="LMARGIN", new_y="NEXT")
208
  pdf.ln(10)
209
 
210
  # Lesion Analysis
211
  pdf.set_font("helvetica", "B", 14)
212
- pdf.cell(txt="Lesion Analysis:", new_x="LMARGIN", new_y="NEXT")
213
  pdf.set_font("helvetica", "", 12)
214
- pdf.cell(txt=f"Bright Lesions: {bright_area:.2f}%", new_x="LMARGIN", new_y="NEXT")
215
- pdf.cell(txt=f"Red Lesions: {red_area:.2f}%", new_x="LMARGIN", new_y="NEXT")
216
- pdf.cell(txt=f"Total Affected Area: {bright_area + red_area:.2f}%", new_x="LMARGIN", new_y="NEXT")
217
  pdf.ln(15)
218
 
219
  # Helper function to add images
@@ -223,7 +223,7 @@ def generate_pdf_report(original_img: Image.Image, mask: np.ndarray, overlay: Im
223
  img_bytes = img_byte_arr.getvalue()
224
 
225
  pdf.set_font("helvetica", "B", 12)
226
- pdf.cell(txt=title, new_x="LMARGIN", new_y="NEXT")
227
  pdf.image(io.BytesIO(img_bytes), x=10, w=180)
228
  pdf.ln(5)
229
 
@@ -235,22 +235,26 @@ def generate_pdf_report(original_img: Image.Image, mask: np.ndarray, overlay: Im
235
  # Footer
236
  pdf.ln(10)
237
  pdf.set_font("helvetica", "I", 10)
238
- pdf.cell(txt="This report was generated by DR Analysis System", new_x="LMARGIN", new_y="NEXT", align='C')
239
 
240
- # Get PDF as bytes
241
- return pdf.output()
 
 
 
242
 
243
  except Exception as e:
244
  st.error(f"PDF generation failed: {str(e)}")
245
  return None
246
-
247
 
248
  # ====================== MAIN APP ======================
249
  def main():
250
  st.set_page_config(layout="wide")
251
  st.title("Diabetic Retinopathy Analysis")
252
 
253
- uploaded_file = st.file_uploader("", type=["jpg", "jpeg", "png"])
 
 
254
  if not uploaded_file:
255
  st.info("Please upload an image")
256
  return
 
91
 
92
  # ====================== CLASSIFIER ======================
93
  def create_classifier_model():
94
+ model = models.resnet152(weights=None) # Modern syntax
95
  num_ftrs = model.fc.in_features
96
  model.fc = nn.Sequential(
97
  nn.Linear(num_ftrs, 512),
 
188
  pdf = FPDF()
189
  pdf.add_page()
190
 
191
+ # Use built-in font that supports basic characters
192
  pdf.set_font("helvetica", "B", 16)
193
+ pdf.cell(text="Diabetic Retinopathy Diagnosis Report", new_x="LMARGIN", new_y="NEXT", align='C')
194
  pdf.ln(10)
195
 
196
  # Patient Info
197
  pdf.set_font("helvetica", "", 12)
198
+ pdf.cell(text="Patient: ___________________________", new_x="LMARGIN", new_y="NEXT")
199
+ pdf.cell(text="Date: _____________________________", new_x="LMARGIN", new_y="NEXT")
200
  pdf.ln(10)
201
 
202
  # Diagnosis
203
  pdf.set_font("helvetica", "B", 14)
204
+ pdf.cell(text="Diagnosis:", new_x="LMARGIN", new_y="NEXT")
205
  pdf.set_font("helvetica", "", 12)
206
+ pdf.cell(text=f"Stage: {diagnosis}", new_x="LMARGIN", new_y="NEXT")
207
+ pdf.cell(text=f"UK Grading: {grade}", new_x="LMARGIN", new_y="NEXT")
208
  pdf.ln(10)
209
 
210
  # Lesion Analysis
211
  pdf.set_font("helvetica", "B", 14)
212
+ pdf.cell(text="Lesion Analysis:", new_x="LMARGIN", new_y="NEXT")
213
  pdf.set_font("helvetica", "", 12)
214
+ pdf.cell(text=f"Bright Lesions: {bright_area:.2f}%", new_x="LMARGIN", new_y="NEXT")
215
+ pdf.cell(text=f"Red Lesions: {red_area:.2f}%", new_x="LMARGIN", new_y="NEXT")
216
+ pdf.cell(text=f"Total Affected Area: {bright_area + red_area:.2f}%", new_x="LMARGIN", new_y="NEXT")
217
  pdf.ln(15)
218
 
219
  # Helper function to add images
 
223
  img_bytes = img_byte_arr.getvalue()
224
 
225
  pdf.set_font("helvetica", "B", 12)
226
+ pdf.cell(text=title, new_x="LMARGIN", new_y="NEXT")
227
  pdf.image(io.BytesIO(img_bytes), x=10, w=180)
228
  pdf.ln(5)
229
 
 
235
  # Footer
236
  pdf.ln(10)
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")
253
  st.title("Diabetic Retinopathy Analysis")
254
 
255
+ uploaded_file = st.file_uploader("Upload retinal scan image",
256
+ type=["jpg", "jpeg", "png"],
257
+ label_visibility="visible")
258
  if not uploaded_file:
259
  st.info("Please upload an image")
260
  return