Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,17 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
import torch
|
| 4 |
from torchvision import models, transforms
|
| 5 |
import PyPDF2 # For reading patient reports (PDFs)
|
| 6 |
|
| 7 |
-
# Load
|
| 8 |
-
model = models.
|
| 9 |
-
model.eval()
|
| 10 |
|
| 11 |
# Define image preprocessing function
|
| 12 |
def preprocess_image(image):
|
| 13 |
transform = transforms.Compose([
|
| 14 |
-
transforms.Resize((224, 224)),
|
| 15 |
transforms.ToTensor(),
|
| 16 |
])
|
| 17 |
return transform(image).unsqueeze(0)
|
|
@@ -27,7 +27,7 @@ def predict_xray(image):
|
|
| 27 |
conditions = ["Normal", "Pneumonia", "Cancer", "TB", "Other"]
|
| 28 |
results = {conditions[i]: float(probs[i]) for i in range(len(conditions))}
|
| 29 |
|
| 30 |
-
#
|
| 31 |
most_likely_condition = max(results, key=results.get)
|
| 32 |
confidence = results[most_likely_condition] * 100 # Convert to percentage
|
| 33 |
|
|
@@ -64,7 +64,7 @@ def predict_xray(image):
|
|
| 64 |
detailed_results += f"<li><b>{condition}:</b> {prob*100:.2f}%</li>"
|
| 65 |
detailed_results += "</ul>"
|
| 66 |
|
| 67 |
-
# Additional
|
| 68 |
additional_feedback = condition_details.get(most_likely_condition, "Please consult with a doctor for further details.")
|
| 69 |
|
| 70 |
return summary, detailed_results, additional_feedback
|
|
|
|
| 1 |
+
]import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
import torch
|
| 4 |
from torchvision import models, transforms
|
| 5 |
import PyPDF2 # For reading patient reports (PDFs)
|
| 6 |
|
| 7 |
+
# Load a more specialized pre-trained model (DenseNet, similar to CheXNet)
|
| 8 |
+
model = models.densenet121(pretrained=True) # DenseNet is good for image classification tasks like chest X-rays
|
| 9 |
+
model.eval() # Set the model to evaluation mode
|
| 10 |
|
| 11 |
# Define image preprocessing function
|
| 12 |
def preprocess_image(image):
|
| 13 |
transform = transforms.Compose([
|
| 14 |
+
transforms.Resize((224, 224)), # Resize to fit the model input size
|
| 15 |
transforms.ToTensor(),
|
| 16 |
])
|
| 17 |
return transform(image).unsqueeze(0)
|
|
|
|
| 27 |
conditions = ["Normal", "Pneumonia", "Cancer", "TB", "Other"]
|
| 28 |
results = {conditions[i]: float(probs[i]) for i in range(len(conditions))}
|
| 29 |
|
| 30 |
+
# Identify the most likely condition and calculate the confidence
|
| 31 |
most_likely_condition = max(results, key=results.get)
|
| 32 |
confidence = results[most_likely_condition] * 100 # Convert to percentage
|
| 33 |
|
|
|
|
| 64 |
detailed_results += f"<li><b>{condition}:</b> {prob*100:.2f}%</li>"
|
| 65 |
detailed_results += "</ul>"
|
| 66 |
|
| 67 |
+
# Additional feedback for the most likely condition
|
| 68 |
additional_feedback = condition_details.get(most_likely_condition, "Please consult with a doctor for further details.")
|
| 69 |
|
| 70 |
return summary, detailed_results, additional_feedback
|