Towhidul commited on
Commit
cabc588
1 Parent(s): 84f2e14

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +147 -0
app.py ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pandas as pd
3
+ import tensorflow as tf
4
+ from tensorflow import keras
5
+ from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout, BatchNormalization, GlobalAveragePooling2D
6
+ from tensorflow.keras.models import Model, load_model, Sequential
7
+ from tensorflow.keras.optimizers import Adam
8
+ from tensorflow.keras.metrics import Precision, Recall
9
+ from tensorflow.keras.callbacks import EarlyStopping
10
+ from sklearn.utils.class_weight import compute_class_weight
11
+ from sklearn.model_selection import train_test_split
12
+
13
+ from tensorflow.keras.utils import to_categorical
14
+ import matplotlib.pyplot as plt
15
+ import warnings
16
+ import warnings
17
+ warnings.filterwarnings("ignore")
18
+
19
+ # print ('modules loaded')
20
+
21
+
22
+ import streamlit as st
23
+ import pandas as pd
24
+ import numpy as np
25
+ from PIL import Image
26
+ import tensorflow.keras as keras
27
+
28
+ st.title("Skin Cancer Classification App")
29
+
30
+ models = {
31
+ "Le_Net": load_model('LeNet_5.h5'),
32
+ "Simple_CNN": load_model('Simple CNN.h5'),
33
+ "Alex_Net": load_model('AlexNet.h5'),
34
+ "Deeper_CNN": load_model('Deeper CNN.h5')
35
+ }
36
+
37
+ # Allow user to select model
38
+ model_name = st.selectbox("Choose a model", list(models.keys()))
39
+ model = models[model_name]
40
+
41
+ # Upload CSV file
42
+ # file = st.file_uploader("Upload a CSV file", type=["csv"])
43
+ file ='hmnist_28_28_RGB.csv'
44
+
45
+ def image_resize(data):
46
+ Data = data.drop(columns=["label"])
47
+ Data = np.array(Data).reshape(-1, 28, 28, 3)
48
+ Data = Data / 255.0 # Normalizing the data
49
+ # Resize images to 32x32 pixels
50
+ Data_resized = resize(Data, [32, 32]).numpy() # Ensure conversion to NumPy array
51
+ return Data_resized
52
+
53
+ if file is not None:
54
+ df = pd.read_csv(file)
55
+ # Get first row
56
+ row = df.iloc[0]
57
+
58
+ # Load image
59
+ image = np.array(Image.open(row[0]))
60
+ # Reshape
61
+ img_reshaped = image_resize(row)
62
+
63
+ # Get prediction
64
+ pred = model.predict(img_reshaped)
65
+ label = np.argmax(pred)
66
+
67
+ label_map = {4: ('nv', ' melanocytic nevi'),
68
+ 6: ('mel', 'melanoma'),
69
+ 2: ('bkl', 'benign keratosis-like lesions'),
70
+ 1: ('bcc' , ' basal cell carcinoma'),
71
+ 5: ('vasc', 'pyogenic granulomas and hemorrhage'),
72
+ 0: ('akiec', 'Actinic keratoses and intraepithelial carcinomae'),
73
+ 3: ('df', 'dermatofibroma')}
74
+
75
+ if label in label_map:
76
+ label_name = label_map[label][0]
77
+ full_name = label_map[label][1]
78
+
79
+ # Display image and result
80
+ col1, col2 = st.columns(2)
81
+ with col1:
82
+ st.header("Input Image")
83
+ st.image(image)
84
+ with col2:
85
+ st.header("Prediction")
86
+ st.metric("Digit", full_name)
87
+
88
+
89
+ # import streamlit as st
90
+ # import predict_model # our prediction model
91
+
92
+ # # Label maps
93
+ # label_map = {0: ('akiec', 'Actinic keratoses'),
94
+ # 1: ('bcc', 'basal cell carcinoma'),
95
+ # # Rest of label map
96
+ # }
97
+
98
+ # # Get prediction
99
+ # img = st.file_uploader("Upload image")
100
+ # if img:
101
+ # pred_id = predict_model.get_prediction(img)
102
+
103
+ # # Display prediction
104
+ # if pred_id in label_map:
105
+ # label_name = label_map[pred_id][0]
106
+ # full_name = label_map[pred_id][1]
107
+
108
+ # st.success(f"Predicted Label: {label_name} - {full_name}")
109
+ # else:
110
+ # st.warning("Unknown label predicted")
111
+
112
+
113
+
114
+ # data_dir = 'hmnist_28_28_RGB.csv'
115
+ # data = pd.read_csv(data_dir)
116
+ # data.head()
117
+
118
+ # Label = data["label"]
119
+ # Data = data.drop(columns=["label"])
120
+
121
+ # data["label"].value_counts()
122
+
123
+ # classes = {4: ('nv', ' melanocytic nevi'),
124
+ # 6: ('mel', 'melanoma'),
125
+ # 2 :('bkl', 'benign keratosis-like lesions'),
126
+ # 1:('bcc' , ' basal cell carcinoma'),
127
+ # 5: ('vasc', ' pyogenic granulomas and hemorrhage'),
128
+ # 0: ('akiec', 'Actinic keratoses and intraepithelial carcinomae'),
129
+ # 3: ('df', 'dermatofibroma')}
130
+
131
+ # from tensorflow.image import resize
132
+
133
+ # #preprocess data
134
+ # Label = data["label"]
135
+
136
+
137
+
138
+ # Label = to_categorical(Label, num_classes=7) # Assuming 7 classes
139
+
140
+
141
+
142
+
143
+ # # Later in Streamlit...
144
+
145
+
146
+
147
+