syaha commited on
Commit
ef408fa
1 Parent(s): 064f7d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -29
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
- from PIL import Image
5
 
6
- # Load model from Hugging Face model repository
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 = 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()
 
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()