File size: 4,065 Bytes
cabc588
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import numpy as np
import pandas as pd
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout, BatchNormalization, GlobalAveragePooling2D
from tensorflow.keras.models import Model, load_model, Sequential
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.metrics import Precision, Recall
from tensorflow.keras.callbacks import EarlyStopping
from sklearn.utils.class_weight import compute_class_weight
from sklearn.model_selection import train_test_split

from tensorflow.keras.utils import to_categorical
import matplotlib.pyplot as plt
import warnings
import warnings
warnings.filterwarnings("ignore")

# print ('modules loaded')


import streamlit as st
import pandas as pd 
import numpy as np
from PIL import Image
import tensorflow.keras as keras

st.title("Skin Cancer Classification App")

models = {
  "Le_Net": load_model('LeNet_5.h5'),
  "Simple_CNN": load_model('Simple CNN.h5'),
  "Alex_Net": load_model('AlexNet.h5'),
  "Deeper_CNN": load_model('Deeper CNN.h5')
}

# Allow user to select model
model_name = st.selectbox("Choose a model", list(models.keys()))
model = models[model_name]

# Upload CSV file 
# file = st.file_uploader("Upload a CSV file", type=["csv"])
file ='hmnist_28_28_RGB.csv'

def image_resize(data):
    Data = data.drop(columns=["label"])
    Data = np.array(Data).reshape(-1, 28, 28, 3)
    Data = Data / 255.0  # Normalizing the data
    # Resize images to 32x32 pixels
    Data_resized = resize(Data, [32, 32]).numpy()  # Ensure conversion to NumPy array
    return Data_resized

if file is not None:
    df = pd.read_csv(file)  
    # Get first row 
    row = df.iloc[0]  
    
    # Load image 
    image = np.array(Image.open(row[0])) 
    # Reshape  
    img_reshaped = image_resize(row)
    
    # Get prediction
    pred = model.predict(img_reshaped)
    label = np.argmax(pred)

    label_map = {4: ('nv', ' melanocytic nevi'), 
             6: ('mel', 'melanoma'),
             2: ('bkl', 'benign keratosis-like lesions'),
             1: ('bcc' , ' basal cell carcinoma'),
             5: ('vasc', 'pyogenic granulomas and hemorrhage'),  
             0: ('akiec', 'Actinic keratoses and intraepithelial carcinomae'),
             3: ('df', 'dermatofibroma')}

    if label in label_map:
        label_name = label_map[label][0]
        full_name = label_map[label][1]
    
    # Display image and result 
    col1, col2 = st.columns(2)
    with col1:
        st.header("Input Image")
        st.image(image)
    with col2:
        st.header("Prediction")
        st.metric("Digit", full_name)


# import streamlit as st
# import predict_model # our prediction model

# # Label maps
# label_map = {0: ('akiec', 'Actinic keratoses'), 
#              1: ('bcc', 'basal cell carcinoma'),
#              # Rest of label map
#              }

# # Get prediction        
# img = st.file_uploader("Upload image")
# if img:
#     pred_id = predict_model.get_prediction(img) 
    
#     # Display prediction    
#     if pred_id in label_map:
#         label_name = label_map[pred_id][0]
#         full_name = label_map[pred_id][1]
        
#         st.success(f"Predicted Label: {label_name} - {full_name}")
#     else:
#         st.warning("Unknown label predicted")        

        

# data_dir = 'hmnist_28_28_RGB.csv'
# data = pd.read_csv(data_dir)
# data.head()

# Label = data["label"]
# Data = data.drop(columns=["label"])

# data["label"].value_counts()

# classes = {4: ('nv', ' melanocytic nevi'),
#            6: ('mel', 'melanoma'),
#            2 :('bkl', 'benign keratosis-like lesions'), 
#            1:('bcc' , ' basal cell carcinoma'),
#            5: ('vasc', ' pyogenic granulomas and hemorrhage'),
#            0: ('akiec', 'Actinic keratoses and intraepithelial carcinomae'),
#            3: ('df', 'dermatofibroma')}

# from tensorflow.image import resize

# #preprocess data
# Label = data["label"]



# Label = to_categorical(Label, num_classes=7)  # Assuming 7 classes




# # Later in Streamlit...