Spaces:
Runtime error
Runtime error
AdithyaSNair
commited on
Commit
·
d6cb779
1
Parent(s):
24e4927
Main commit
Browse files- Mild.jpg +0 -0
- Mild1.jpg +0 -0
- Moderate.jpg +0 -0
- Moderate1.jpg +0 -0
- Non (1).jpg +0 -0
- Non (2).jpg +0 -0
- Very (1).jpg +0 -0
- Very (2).jpg +0 -0
- app.py +57 -0
- requirements.txt +7 -0
Mild.jpg
ADDED
Mild1.jpg
ADDED
Moderate.jpg
ADDED
Moderate1.jpg
ADDED
Non (1).jpg
ADDED
Non (2).jpg
ADDED
Very (1).jpg
ADDED
Very (2).jpg
ADDED
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import os
|
3 |
+
import keras
|
4 |
+
import pandas as pd
|
5 |
+
import seaborn as sns
|
6 |
+
import matplotlib.pyplot as plt
|
7 |
+
from keras.models import Sequential
|
8 |
+
from PIL import Image
|
9 |
+
from keras.layers import Conv2D, Flatten, Dense, Dropout, BatchNormalization, MaxPooling2D
|
10 |
+
from sklearn.preprocessing import OneHotEncoder
|
11 |
+
import pickle
|
12 |
+
import gradio as gr
|
13 |
+
|
14 |
+
def load_model():
|
15 |
+
save_path = 'model.pkl'
|
16 |
+
with open(save_path, 'rb') as file:
|
17 |
+
model = pickle.load(file)
|
18 |
+
return model
|
19 |
+
|
20 |
+
def predict_dementia(images, model):
|
21 |
+
predictions = []
|
22 |
+
for image in images:
|
23 |
+
img = Image.fromarray(image.astype('uint8'))
|
24 |
+
img = img.resize((128, 128))
|
25 |
+
img = np.array(img)
|
26 |
+
img = img.reshape(1, 128, 128, 3)
|
27 |
+
|
28 |
+
prediction = model.predict(img)
|
29 |
+
prediction_class = np.argmax(prediction)
|
30 |
+
predictions.append(names(prediction_class))
|
31 |
+
return predictions
|
32 |
+
|
33 |
+
def names(number):
|
34 |
+
if number == 0:
|
35 |
+
return 'Non Demented'
|
36 |
+
elif number == 1:
|
37 |
+
return 'Mild Dementia'
|
38 |
+
elif number == 2:
|
39 |
+
return 'Moderate Dementia'
|
40 |
+
elif number == 3:
|
41 |
+
return 'Very Mild Dementia'
|
42 |
+
else:
|
43 |
+
return 'Error in Prediction'
|
44 |
+
|
45 |
+
def main(images):
|
46 |
+
model = load_model()
|
47 |
+
predictions = predict_dementia(images, model)
|
48 |
+
return predictions
|
49 |
+
|
50 |
+
iface = gr.Interface(fn=main,
|
51 |
+
inputs="image",
|
52 |
+
outputs="text",
|
53 |
+
title="Dementia Classification",
|
54 |
+
description="Classify dementia based on brain images",
|
55 |
+
examples=[["Non(1).jpg"],["Moderate.jpg"],["Mild.jpg"]])
|
56 |
+
|
57 |
+
iface.launch(debug =True)
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
tensorflow
|
3 |
+
numpy
|
4 |
+
pandas
|
5 |
+
matplotlib
|
6 |
+
scikit-learn
|
7 |
+
seaborn
|