Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,31 @@
|
|
1 |
import gradio as gr
|
2 |
from tensorflow.keras.models import load_model
|
3 |
import numpy as np
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
model = load_model("syaha/skin_cancer_detection_model")
|
8 |
|
9 |
-
# Preprocess function
|
10 |
-
def preprocess_image(image):
|
11 |
-
image = image.resize((224, 224)) # Resize to match model input size
|
12 |
-
image = np.array(image) / 255.0 # Normalize
|
13 |
-
image = np.expand_dims(image, axis=0) # Add batch dimension
|
14 |
-
return image
|
15 |
-
|
16 |
-
# Predict function
|
17 |
def predict_image(image):
|
18 |
-
img =
|
|
|
|
|
|
|
19 |
prediction = model.predict(img)
|
20 |
predicted_class = np.argmax(prediction, axis=1)[0]
|
21 |
-
|
22 |
-
class_label = disease_info[predicted_class]['name']
|
23 |
-
description = disease_info[predicted_class]['description']
|
24 |
-
|
25 |
-
return f"Prediction: {class_label}\nDescription: {description}"
|
26 |
|
27 |
-
|
28 |
-
disease_info = {
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
}
|
|
|
|
|
37 |
|
38 |
-
# Gradio
|
39 |
iface = gr.Interface(fn=predict_image, inputs="image", outputs="text")
|
40 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from tensorflow.keras.models import load_model
|
3 |
import numpy as np
|
4 |
+
import tensorflow as tf
|
5 |
|
6 |
+
model = load_model("skin_cancer_detection_model.h5")
|
|
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def predict_image(image):
|
9 |
+
img = tf.image.resize(image, (224, 224))
|
10 |
+
img = np.expand_dims(img, axis=0)
|
11 |
+
img = img / 255.0
|
12 |
+
|
13 |
prediction = model.predict(img)
|
14 |
predicted_class = np.argmax(prediction, axis=1)[0]
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
class_names = ['akiec', 'bcc', 'bkl', 'df', 'nv', 'vasc', 'mel']
|
17 |
+
disease_info = {
|
18 |
+
'akiec': "Actinic Keratoses and Intraepithelial Carcinoma (pre-cancerous lesion)",
|
19 |
+
'bcc': "Basal Cell Carcinoma (a common type of skin cancer)",
|
20 |
+
'bkl': "Benign Keratosis (non-cancerous lesion)",
|
21 |
+
'df': "Dermatofibroma (benign skin lesion)",
|
22 |
+
'nv': "Melanocytic Nevus (a common mole)",
|
23 |
+
'vasc': "Vascular Lesions (benign lesion of blood vessels)",
|
24 |
+
'mel': "Melanoma (most dangerous type of skin cancer)"
|
25 |
+
}
|
26 |
+
|
27 |
+
return f"{class_names[predicted_class]}: {disease_info[class_names[predicted_class]]}"
|
28 |
|
29 |
+
# Gradio Interface
|
30 |
iface = gr.Interface(fn=predict_image, inputs="image", outputs="text")
|
31 |
+
iface.launch()
|