Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -57,10 +57,6 @@ transform = transforms.Compose([
|
|
| 57 |
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
|
| 58 |
])
|
| 59 |
|
| 60 |
-
# Helper to sanitize filename
|
| 61 |
-
def clean_filename(name):
|
| 62 |
-
return "".join(c for c in name if c.isalnum() or c in (' ', '_', '-')).rstrip()
|
| 63 |
-
|
| 64 |
# Prediction and PDF generation function
|
| 65 |
def predict(image, patient_name, xray_date):
|
| 66 |
if image is None:
|
|
@@ -98,7 +94,7 @@ def predict(image, patient_name, xray_date):
|
|
| 98 |
else:
|
| 99 |
comment = f"🔎 Possible {top_label}, but confidence is low."
|
| 100 |
|
| 101 |
-
# Generate PDF
|
| 102 |
pdf = FPDF()
|
| 103 |
pdf.add_page()
|
| 104 |
pdf.set_font("Arial", 'B', 16)
|
|
@@ -108,8 +104,8 @@ def predict(image, patient_name, xray_date):
|
|
| 108 |
# Patient Details
|
| 109 |
pdf.set_font("Arial", '', 12)
|
| 110 |
pdf.cell(0, 10, f"Patient Name: {patient_name}", ln=True)
|
| 111 |
-
pdf.cell(0, 10, f"
|
| 112 |
-
pdf.cell(0, 10, f"Report
|
| 113 |
pdf.ln(10)
|
| 114 |
|
| 115 |
# Top 5 Predictions
|
|
@@ -128,12 +124,11 @@ def predict(image, patient_name, xray_date):
|
|
| 128 |
pdf.set_font("Arial", '', 12)
|
| 129 |
pdf.multi_cell(0, 10, comment)
|
| 130 |
|
| 131 |
-
# Save PDF
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
pdf.output(report_filename)
|
| 135 |
|
| 136 |
-
return
|
| 137 |
|
| 138 |
# Gradio Interface
|
| 139 |
interface = gr.Interface(
|
|
|
|
| 57 |
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
|
| 58 |
])
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
# Prediction and PDF generation function
|
| 61 |
def predict(image, patient_name, xray_date):
|
| 62 |
if image is None:
|
|
|
|
| 94 |
else:
|
| 95 |
comment = f"🔎 Possible {top_label}, but confidence is low."
|
| 96 |
|
| 97 |
+
# Generate PDF report
|
| 98 |
pdf = FPDF()
|
| 99 |
pdf.add_page()
|
| 100 |
pdf.set_font("Arial", 'B', 16)
|
|
|
|
| 104 |
# Patient Details
|
| 105 |
pdf.set_font("Arial", '', 12)
|
| 106 |
pdf.cell(0, 10, f"Patient Name: {patient_name}", ln=True)
|
| 107 |
+
pdf.cell(0, 10, f"X-ray Date: {xray_date}", ln=True)
|
| 108 |
+
pdf.cell(0, 10, f"Report Date: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}", ln=True)
|
| 109 |
pdf.ln(10)
|
| 110 |
|
| 111 |
# Top 5 Predictions
|
|
|
|
| 124 |
pdf.set_font("Arial", '', 12)
|
| 125 |
pdf.multi_cell(0, 10, comment)
|
| 126 |
|
| 127 |
+
# Save PDF
|
| 128 |
+
output_pdf_path = "chest_xray_report.pdf"
|
| 129 |
+
pdf.output(output_pdf_path)
|
|
|
|
| 130 |
|
| 131 |
+
return output_pdf_path
|
| 132 |
|
| 133 |
# Gradio Interface
|
| 134 |
interface = gr.Interface(
|