Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from tensorflow.keras.models import load_model
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
# Load model from Hugging Face model repository
|
7 |
+
model = load_model("https://huggingface.co/syaha/skin_cancer_detection_model/resolve/main/skin_cancer_detection_model.h5")
|
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 = preprocess_image(image)
|
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 |
+
# Disease information mapping
|
28 |
+
disease_info = {
|
29 |
+
0: {'name': 'Actinic Keratoses (akiec)', 'description': 'Rough, scaly patches caused by sun exposure.'},
|
30 |
+
1: {'name': 'Basal Cell Carcinoma (bcc)', 'description': 'A type of skin cancer that rarely spreads.'},
|
31 |
+
2: {'name': 'Benign Keratosis (bkl)', 'description': 'Non-cancerous skin lesions.'},
|
32 |
+
3: {'name': 'Dermatofibroma (df)', 'description': 'A benign lesion often on the legs.'},
|
33 |
+
4: {'name': 'Melanocytic Nevus (nv)', 'description': 'Common mole, can develop into melanoma.'},
|
34 |
+
5: {'name': 'Vascular Lesions (vasc)', 'description': 'Blood vessel-related skin growths.'},
|
35 |
+
6: {'name': 'Melanoma (mel)', 'description': 'Most dangerous skin cancer, early detection is key.'}
|
36 |
+
}
|
37 |
+
|
38 |
+
# Gradio interface
|
39 |
+
iface = gr.Interface(fn=predict_image, inputs="image", outputs="text")
|
40 |
+
iface.launch()
|