Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
import numpy as np
|
4 |
+
import nibabel as nib
|
5 |
+
from model import My3DModel
|
6 |
+
|
7 |
+
model = My3DModel()
|
8 |
+
model.load_state_dict(torch.load("model.pt", map_location="cpu"))
|
9 |
+
model.eval()
|
10 |
+
|
11 |
+
def predict_from_mri(file_obj):
|
12 |
+
img = nib.load(file_obj.name)
|
13 |
+
data = img.get_fdata().astype(np.float32)
|
14 |
+
data = np.expand_dims(data, axis=0) # (1, D, H, W)
|
15 |
+
tensor = torch.tensor(data).unsqueeze(0) # (1, 1, D, H, W)
|
16 |
+
|
17 |
+
with torch.no_grad():
|
18 |
+
output = model(tensor)
|
19 |
+
pred_class = torch.argmax(output, dim=1).item()
|
20 |
+
|
21 |
+
return ["CN", "MCI", "AD"][pred_class]
|
22 |
+
|
23 |
+
iface = gr.Interface(fn=predict_from_mri,
|
24 |
+
inputs=gr.File(label="MRI .nii dosyası"),
|
25 |
+
outputs="text",
|
26 |
+
title="3D MRI Alzheimer Teşhis Modeli")
|
27 |
+
iface.launch()
|