Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torch.nn as nn
|
3 |
+
from torchvision import transforms
|
4 |
+
from PIL import Image
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
model.load_state_dict(torch.load("squeezenet.pth"))
|
8 |
+
model.eval()
|
9 |
+
|
10 |
+
transform = transforms.Compose([
|
11 |
+
transforms.Resize((128, 128)),
|
12 |
+
transforms.ToTensor(),
|
13 |
+
transforms.Normalize([0.5], [0.5])
|
14 |
+
])
|
15 |
+
|
16 |
+
def classify_brain_tumor(image):
|
17 |
+
image = transform(image).unsqueeze(0)
|
18 |
+
with torch.no_grad():
|
19 |
+
output = model(image)
|
20 |
+
_, predicted = torch.max(output, 1)
|
21 |
+
return "Tumor" if predicted.item() == 1 else "No Tumor"
|
22 |
+
|
23 |
+
interface = gr.Interface(
|
24 |
+
fn=classify_brain_tumor,
|
25 |
+
inputs=gr.inputs.Image(type="pil"),
|
26 |
+
outputs="text",
|
27 |
+
title="Brain Tumor Classification",
|
28 |
+
description="Upload an MRI image to classify if it has a tumor or not. The Model is SqueezeNet."
|
29 |
+
)
|
30 |
+
|
31 |
+
interface.launch()
|