Suweeraya commited on
Commit
75b972c
·
1 Parent(s): 87ccb58

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import tensorflow as tf
4
+ from tensorflow import keras
5
+ from PIL import Image
6
+
7
+ model = keras.models.load_model("skinCancerClassification_UsningCNN.h5")
8
+
9
+ class_labels = {
10
+ 0: 'dermatofibroma',
11
+ 1: 'melanoma',
12
+ 2: 'nevus',
13
+ 3: 'seborrheic keratosis',
14
+ 4: 'squamous cell carcinoma',
15
+ 5: 'pigmented benign keratosis',
16
+ 6: 'basal cell carcinoma',
17
+ 7: 'vascular lesion',
18
+ 8: 'actinic keratosis'
19
+ }
20
+
21
+ def classify_skin_cancer(image):
22
+ # Preprocess the image
23
+ image = np.array(image)
24
+ image = tf.image.resize(image, (75, 100)) # Resize to match model input shape
25
+ image = np.expand_dims(image, axis=0)
26
+
27
+ predictions = model.predict(image)
28
+ class_index = np.argmax(predictions)
29
+ class_name = class_labels[class_index]
30
+
31
+ confidence = np.max(predictions)
32
+
33
+ return f"Predicted Class: {class_name}\nConfidence: {confidence:.2f}"
34
+
35
+ iface = gr.Interface(
36
+ fn=classify_skin_cancer,
37
+ inputs="image",
38
+ outputs="text",
39
+ live=True,
40
+ title="Skin Cancer Classification",
41
+ description="Upload an image of a skin lesion to classify its type."
42
+ )
43
+
44
+ iface.launch()