HumzaAli commited on
Commit
eebd2c1
·
verified ·
1 Parent(s): daed886

Create app.py file

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from PIL import Image
4
+ import tensorflow as tf
5
+ from keras.preprocessing import image
6
+ from keras.models import load_model
7
+
8
+ # Load the trained model
9
+ model_path = 'SCDSNet-H10K_Model-1.keras'
10
+ model = load_model(model_path)
11
+
12
+ # Define the class labels
13
+ classes = ['akiec', 'bcc', 'bkl', 'df', 'melanoma', 'nv', 'vasc']
14
+
15
+ # Function to preprocess the image
16
+ def preprocess_image(image_bytes):
17
+ img = Image.open(image_bytes).convert('RGB')
18
+ img = img.resize((32, 32))
19
+ img_array = image.img_to_array(img)
20
+ img_array = np.expand_dims(img_array, axis=0)
21
+ img_array = img_array / 255.0
22
+ return img_array
23
+
24
+ # Function to predict class label and probability
25
+ def predict_image(image_bytes):
26
+ img_array = preprocess_image(image_bytes)
27
+ predictions = model.predict(img_array)
28
+ score = tf.nn.softmax(predictions[0])
29
+ predicted_class = classes[np.argmax(score)]
30
+ return predicted_class
31
+
32
+ # Create a Gradio interface
33
+ iface = gr.Interface(
34
+ fn=predict_image,
35
+ inputs="file",
36
+ outputs=["label"],
37
+ title="Skin Cancer Classification",
38
+ description="Upload an image of a skin lesion for classification."
39
+ )
40
+
41
+ # Launch the interface
42
+ iface.launch()