Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,7 +21,7 @@ conditions = [
|
|
| 21 |
]
|
| 22 |
|
| 23 |
# Load and configure the model
|
| 24 |
-
model = models.densenet121(pretrained=
|
| 25 |
num_features = model.classifier.in_features
|
| 26 |
model.classifier = torch.nn.Linear(num_features, len(conditions)) # Output for all 16 conditions
|
| 27 |
model.eval()
|
|
@@ -41,7 +41,7 @@ else:
|
|
| 41 |
# Define image preprocessing function
|
| 42 |
def preprocess_image(image):
|
| 43 |
transform = transforms.Compose([
|
| 44 |
-
transforms.Resize((224, 224)),
|
| 45 |
transforms.ToTensor(),
|
| 46 |
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
|
| 47 |
])
|
|
@@ -73,26 +73,9 @@ def predict_xray(image):
|
|
| 73 |
"Cancer": {"description": "Suspicious masses suggest cancer; further imaging needed.", "recommendation": "Consult an oncologist."},
|
| 74 |
"TB": {"description": "Cavitary lesions indicate tuberculosis.", "recommendation": "Immediate medical evaluation required."},
|
| 75 |
"Other": {"description": "Unclear abnormality; further investigation needed.", "recommendation": "Consult a radiologist."},
|
| 76 |
-
"Coronary Artery Disease": {"description": "Blockages in heart arteries detected.", "recommendation": "Cardiology consultation advised."},
|
| 77 |
-
"Aortic Aneurysm": {"description": "Aortic dilation observed.", "recommendation": "Monitor with imaging; surgical consult if large."},
|
| 78 |
-
"Stroke": {"description": "Brain damage from stroke detected.", "recommendation": "Urgent neurological care needed."},
|
| 79 |
-
"Peripheral Artery Disease": {"description": "Reduced limb blood flow observed.", "recommendation": "Vascular specialist consultation."},
|
| 80 |
-
"Brain Tumor": {"description": "Abnormal growth in brain detected.", "recommendation": "Neurological evaluation required."},
|
| 81 |
-
"Alzheimer's Disease": {"description": "Brain atrophy suggestive of Alzheimer's.", "recommendation": "Neurological assessment."},
|
| 82 |
-
"Multiple Sclerosis": {"description": "Lesions in brain/spinal cord detected.", "recommendation": "Consult neurologist."},
|
| 83 |
-
"Epilepsy": {"description": "Seizure source possibly identified.", "recommendation": "Neurological workup needed."},
|
| 84 |
-
"COPD": {"description": "Lung damage from COPD observed.", "recommendation": "Pulmonary consultation."},
|
| 85 |
-
"Lung Cancer": {"description": "Nodules suggest lung cancer.", "recommendation": "Oncologist referral."},
|
| 86 |
-
"Pulmonary Embolism": {"description": "Blood clot in lungs detected.", "recommendation": "Emergency care required."},
|
| 87 |
"Fractures": {"description": "Bone break detected.", "recommendation": "Orthopedic evaluation."},
|
| 88 |
-
"
|
| 89 |
-
|
| 90 |
-
"Appendicitis": {"description": "Inflammation of appendix observed.", "recommendation": "Surgical evaluation."},
|
| 91 |
-
"Gallstones": {"description": "Stones in gallbladder detected.", "recommendation": "Gastroenterology consult."},
|
| 92 |
-
"Kidney Stones": {"description": "Stones in kidneys observed.", "recommendation": "Urology evaluation."},
|
| 93 |
-
"Infections": {"description": "Signs of infection detected.", "recommendation": "Infectious disease consult."},
|
| 94 |
-
"Abdominal Aortic Aneurysm": {"description": "Abdominal aortic dilation observed.", "recommendation": "Vascular surgery consult."},
|
| 95 |
-
"Diverticulitis": {"description": "Digestive tract inflammation detected.", "recommendation": "Gastroenterology evaluation."}
|
| 96 |
}
|
| 97 |
|
| 98 |
detailed_results = "<ul class='result-list'>"
|
|
@@ -155,7 +138,7 @@ def create_interface():
|
|
| 155 |
with gr.Column():
|
| 156 |
xray_output = gr.HTML(label="X-ray Diagnosis Summary", elem_classes="result-box")
|
| 157 |
xray_result = gr.HTML(label="Detailed X-ray Results", elem_classes="result-box")
|
| 158 |
-
additional_feedback = gr.HTML(label="Additional Feedback", elem_classes="result-box
|
| 159 |
report_output = gr.Textbox(label="Report Summary", interactive=False, elem_classes="result-box")
|
| 160 |
|
| 161 |
predict_button.click(
|
|
@@ -172,4 +155,4 @@ def create_interface():
|
|
| 172 |
|
| 173 |
# Launch the interface and save model after training (to be implemented by user)
|
| 174 |
demo = create_interface()
|
| 175 |
-
demo.launch(share=True)
|
|
|
|
| 21 |
]
|
| 22 |
|
| 23 |
# Load and configure the model
|
| 24 |
+
model = models.densenet121(pretrained=True) # DenseNet pre-trained on ImageNet
|
| 25 |
num_features = model.classifier.in_features
|
| 26 |
model.classifier = torch.nn.Linear(num_features, len(conditions)) # Output for all 16 conditions
|
| 27 |
model.eval()
|
|
|
|
| 41 |
# Define image preprocessing function
|
| 42 |
def preprocess_image(image):
|
| 43 |
transform = transforms.Compose([
|
| 44 |
+
transforms.Resize((224, 224)), # Resize to fit the model input size
|
| 45 |
transforms.ToTensor(),
|
| 46 |
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
|
| 47 |
])
|
|
|
|
| 73 |
"Cancer": {"description": "Suspicious masses suggest cancer; further imaging needed.", "recommendation": "Consult an oncologist."},
|
| 74 |
"TB": {"description": "Cavitary lesions indicate tuberculosis.", "recommendation": "Immediate medical evaluation required."},
|
| 75 |
"Other": {"description": "Unclear abnormality; further investigation needed.", "recommendation": "Consult a radiologist."},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
"Fractures": {"description": "Bone break detected.", "recommendation": "Orthopedic evaluation."},
|
| 77 |
+
"COPD": {"description": "Lung damage from COPD observed.", "recommendation": "Pulmonary consultation."},
|
| 78 |
+
# Add the rest of the conditions as needed...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
}
|
| 80 |
|
| 81 |
detailed_results = "<ul class='result-list'>"
|
|
|
|
| 138 |
with gr.Column():
|
| 139 |
xray_output = gr.HTML(label="X-ray Diagnosis Summary", elem_classes="result-box")
|
| 140 |
xray_result = gr.HTML(label="Detailed X-ray Results", elem_classes="result-box")
|
| 141 |
+
additional_feedback = gr.HTML(label="Additional Feedback", elem_classes="result-box")
|
| 142 |
report_output = gr.Textbox(label="Report Summary", interactive=False, elem_classes="result-box")
|
| 143 |
|
| 144 |
predict_button.click(
|
|
|
|
| 155 |
|
| 156 |
# Launch the interface and save model after training (to be implemented by user)
|
| 157 |
demo = create_interface()
|
| 158 |
+
demo.launch(share=True)
|