Spaces:
Runtime error
Runtime error
| 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() | |