Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -101,20 +101,42 @@ def predict_xray(image):
|
|
| 101 |
logger.error(f"Error in predict_xray: {str(e)}")
|
| 102 |
return f"Error: {str(e)}", "", ""
|
| 103 |
|
| 104 |
-
#
|
| 105 |
def analyze_report(file):
|
| 106 |
text = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
if file and file.name.endswith(".pdf"):
|
| 108 |
try:
|
| 109 |
pdf_reader = PyPDF2.PdfReader(file)
|
| 110 |
for page in pdf_reader.pages:
|
| 111 |
text += page.extract_text() or ""
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
except Exception as e:
|
| 114 |
logger.error(f"Error reading PDF: {str(e)}")
|
| 115 |
report_summary = f"Error processing PDF: {str(e)}"
|
| 116 |
else:
|
| 117 |
report_summary = "Please upload a valid PDF file."
|
|
|
|
| 118 |
return report_summary
|
| 119 |
|
| 120 |
# Gradio Interface with enhanced UI
|
|
|
|
| 101 |
logger.error(f"Error in predict_xray: {str(e)}")
|
| 102 |
return f"Error: {str(e)}", "", ""
|
| 103 |
|
| 104 |
+
# Enhanced function to analyze patient reports (PDFs)
|
| 105 |
def analyze_report(file):
|
| 106 |
text = ""
|
| 107 |
+
patient_condition = "Unclear"
|
| 108 |
+
disease = "Unknown"
|
| 109 |
+
status = "Pending further tests"
|
| 110 |
+
|
| 111 |
if file and file.name.endswith(".pdf"):
|
| 112 |
try:
|
| 113 |
pdf_reader = PyPDF2.PdfReader(file)
|
| 114 |
for page in pdf_reader.pages:
|
| 115 |
text += page.extract_text() or ""
|
| 116 |
+
|
| 117 |
+
# Example: Let's search for conditions in the text
|
| 118 |
+
if "stroke" in text.lower():
|
| 119 |
+
patient_condition = "Stroke"
|
| 120 |
+
disease = "Brain Disorder"
|
| 121 |
+
status = "Urgent Care Needed"
|
| 122 |
+
elif "cancer" in text.lower():
|
| 123 |
+
patient_condition = "Cancer"
|
| 124 |
+
disease = "Malignant Growth"
|
| 125 |
+
status = "Consult Oncologist"
|
| 126 |
+
elif "fracture" in text.lower():
|
| 127 |
+
patient_condition = "Fracture"
|
| 128 |
+
disease = "Bone Injury"
|
| 129 |
+
status = "Orthopedic Attention Required"
|
| 130 |
+
# You can add more conditions here based on keyword matching
|
| 131 |
+
|
| 132 |
+
report_summary = f"Patient's Condition: {patient_condition}\nDisease: {disease}\nCondition Status: {status}\n\nReport Preview: {text[:300]}..." if text else "No readable text found in the PDF."
|
| 133 |
+
|
| 134 |
except Exception as e:
|
| 135 |
logger.error(f"Error reading PDF: {str(e)}")
|
| 136 |
report_summary = f"Error processing PDF: {str(e)}"
|
| 137 |
else:
|
| 138 |
report_summary = "Please upload a valid PDF file."
|
| 139 |
+
|
| 140 |
return report_summary
|
| 141 |
|
| 142 |
# Gradio Interface with enhanced UI
|