File size: 1,263 Bytes
d6cb779
 
 
 
 
 
 
 
 
 
 
79a1c68
d6cb779
 
16617ac
 
 
d6cb779
16617ac
 
d6cb779
16617ac
 
 
 
 
 
 
 
 
 
d6cb779
16617ac
 
 
 
 
 
 
 
 
 
d6cb779
16617ac
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import numpy as np
import os
import keras
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from keras.models import Sequential
from PIL import Image
from keras.layers import Conv2D, Flatten, Dense, Dropout, BatchNormalization, MaxPooling2D
from sklearn.preprocessing import OneHotEncoder
import pickle
import tensorflow as tf
import gradio as gr

# Load the model
model_path = "model.pkl"
model = tf.keras.models.load_model(model_path)

# Define the labels
labels = ['Non Demented', 'Mild Dementia', 'Moderate Dementia', 'Very Mild Dementia']

# Define the prediction function
def predict_dementia(image):
    img = Image.fromarray(image.astype('uint8'))
    img = img.resize((128, 128))
    img = np.array(img)
    img = img.reshape(1, 128, 128, 3)
    
    prediction = model.predict(img)
    prediction_class = np.argmax(prediction)
    return labels[prediction_class]

# Create the Gradio interface
iface = gr.Interface(
    fn=predict_dementia,
    inputs="image",
    outputs="text",
    title="Dementia Classification",
    description="Classify dementia based on brain images",
    examples=[["Non(1).jpg"],["Mild.jpg"],["Moderate.jpg"],["Very(1).jpg"]],
    allow_flagging=False
)

# Launch the interface
iface.launch(debug=True)