File size: 2,031 Bytes
0e5da45
 
 
567dd0d
0e5da45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f0373f1
0e5da45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import gradio as gr
import tensorflow as tf
import numpy as np


# Load the Xception model
model = tf.keras.models.load_model("Xception_skin.h5")  # Replace with your model path

# Define a function for inference and confidence values
def classify_image(input_image):
    # Preprocess the image
    img = input_image.resize((299, 299))  # Ensure the image size matches your Xception model's input size
    img = np.array(img) / 255.0  # Normalize the image
    img = np.expand_dims(img, axis=0)  # Add batch dimension

    # Perform classification
    predictions = model.predict(img)
    class_index = np.argmax(predictions[0])  # Get the index of the predicted class
    confidence_values = predictions[0]  # Get confidence values for all classes

    # Map the class index to the corresponding class name using the provided dictionary
    class_names = {
        0: 'Eczema',
        1: 'Warts Molluscum and other Viral Infections',
        2: 'Melanoma',
        3: 'Atopic Dermatitis',
        4: 'Basal Cell Carcinoma (BCC)',
        5: 'Melanocytic Nevi (NV) ',
        6: 'Benign Keratosis-like Lesions (BKL)',
        7: 'Psoriasis pictures Lichen Planus and related diseases',
        8: 'Seborrheic Keratoses and other Benign Tumors',
        9: 'Tinea Ringworm Candidiasis and other Fungal Infections'
    }
    confidences = {class_names[i]: float(confidence_values[i]) for i in range(len(confidence_values))} 
    #predicted_class_name = class_names[class_index]  # Get the class name based on the index

    return  confidences

# Define the Gradio interface
input_image = gr.inputs.Image(type="pil")
#output_class_name = gr.outputs.Label(type='text', label='Predicted Class Name')
output_confidence_values = gr.outputs.Label(type='text', label='Confidence Values')

# Create the Gradio app
app = gr.Interface(
    fn=classify_image,
    inputs=input_image,
    outputs=output_confidence_values,
    title='Skin Disease Classifier',
    description='Made By Roshan Rateria',
)

# Launch the Gradio app
app.launch()