Conn Finnegan
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,10 +9,10 @@ model.fc = torch.nn.Linear(model.fc.in_features, 2)
|
|
| 9 |
model.load_state_dict(torch.load("skin_cancer_resnet18_version1.pt", map_location="cpu"))
|
| 10 |
model.eval()
|
| 11 |
|
| 12 |
-
#
|
| 13 |
classes = ['benign', 'malignant']
|
| 14 |
|
| 15 |
-
#
|
| 16 |
transform = transforms.Compose([
|
| 17 |
transforms.Resize((224, 224)),
|
| 18 |
transforms.ToTensor()
|
|
@@ -27,13 +27,21 @@ def predict(img):
|
|
| 27 |
probs = torch.nn.functional.softmax(output[0], dim=0)
|
| 28 |
return {classes[i]: float(probs[i]) for i in range(2)}
|
| 29 |
|
| 30 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
demo = gr.Interface(
|
| 32 |
fn=predict,
|
| 33 |
-
inputs=gr.Image(type="pil", label="Upload
|
| 34 |
-
outputs=gr.Label(num_top_classes=2),
|
| 35 |
-
title=
|
| 36 |
-
description=
|
| 37 |
)
|
| 38 |
|
| 39 |
demo.launch()
|
|
|
|
| 9 |
model.load_state_dict(torch.load("skin_cancer_resnet18_version1.pt", map_location="cpu"))
|
| 10 |
model.eval()
|
| 11 |
|
| 12 |
+
# Class labels
|
| 13 |
classes = ['benign', 'malignant']
|
| 14 |
|
| 15 |
+
# Image preprocessing
|
| 16 |
transform = transforms.Compose([
|
| 17 |
transforms.Resize((224, 224)),
|
| 18 |
transforms.ToTensor()
|
|
|
|
| 27 |
probs = torch.nn.functional.softmax(output[0], dim=0)
|
| 28 |
return {classes[i]: float(probs[i]) for i in range(2)}
|
| 29 |
|
| 30 |
+
# UI text
|
| 31 |
+
title = "🧠 Lumen: Skin Cancer Classifier"
|
| 32 |
+
description = """
|
| 33 |
+
Upload a dermoscopic image of a mole or skin lesion.<br>
|
| 34 |
+
The model will classify it as <b>benign</b> or <b>malignant</b> based on its appearance.<br><br>
|
| 35 |
+
<b>Disclaimer:</b> This tool is for research and educational use only. It is not a diagnostic device.
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
# Gradio Interface
|
| 39 |
demo = gr.Interface(
|
| 40 |
fn=predict,
|
| 41 |
+
inputs=gr.Image(type="pil", label="Upload Lesion Image"),
|
| 42 |
+
outputs=gr.Label(num_top_classes=2, label="Prediction"),
|
| 43 |
+
title=title,
|
| 44 |
+
description=description
|
| 45 |
)
|
| 46 |
|
| 47 |
demo.launch()
|