Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
from PIL import Image
|
| 3 |
import torch
|
| 4 |
from torchvision import models, transforms
|
| 5 |
-
import
|
| 6 |
import logging
|
| 7 |
import os
|
| 8 |
|
|
@@ -101,7 +101,7 @@ def predict_xray(image):
|
|
| 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"
|
|
@@ -110,10 +110,11 @@ def analyze_report(file):
|
|
| 110 |
|
| 111 |
if file and file.name.endswith(".pdf"):
|
| 112 |
try:
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
| 117 |
# Example: Let's search for conditions in the text
|
| 118 |
if "stroke" in text.lower():
|
| 119 |
patient_condition = "Stroke"
|
|
|
|
| 2 |
from PIL import Image
|
| 3 |
import torch
|
| 4 |
from torchvision import models, transforms
|
| 5 |
+
import fitz # PyMuPDF for better PDF parsing
|
| 6 |
import logging
|
| 7 |
import os
|
| 8 |
|
|
|
|
| 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) using PyMuPDF (fitz)
|
| 105 |
def analyze_report(file):
|
| 106 |
text = ""
|
| 107 |
patient_condition = "Unclear"
|
|
|
|
| 110 |
|
| 111 |
if file and file.name.endswith(".pdf"):
|
| 112 |
try:
|
| 113 |
+
# Open the PDF using PyMuPDF
|
| 114 |
+
pdf_reader = fitz.open(file.name)
|
| 115 |
+
for page in pdf_reader:
|
| 116 |
+
text += page.get_text("text") # Extract text from each page
|
| 117 |
+
|
| 118 |
# Example: Let's search for conditions in the text
|
| 119 |
if "stroke" in text.lower():
|
| 120 |
patient_condition = "Stroke"
|