Spaces:
Running
Running
| import gradio as gr | |
| from tensorflow.keras.models import load_model | |
| from tensorflow.keras.preprocessing import image | |
| import numpy as np | |
| # Load the trained model | |
| model = load_model("best_model.keras") | |
| # Define disease labels | |
| disease_labels = [ | |
| "Cellulitis", "Impetigo", "Athlete's Foot", "Nail Fungus", | |
| "Ringworm", "Cutaneous Larva Migrans", "Chickenpox", "Shingles" | |
| ] | |
| # Define the prediction function | |
| def predict_disease(img): | |
| # Preprocess the image | |
| img = img.resize((224, 224)) | |
| img_array = image.img_to_array(img) | |
| img_array = np.expand_dims(img_array, axis=0) | |
| img_array /= 255.0 # Normalize to [0, 1] range | |
| # Make prediction | |
| predictions = model.predict(img_array) | |
| predicted_index = np.argmax(predictions) | |
| # Return the predicted disease | |
| return disease_labels[predicted_index] | |
| # Create Gradio interface | |
| iface = gr.Interface( | |
| fn=predict_disease, | |
| inputs=gr.Image(type="pil"), | |
| outputs=gr.Textbox(), | |
| title="Skin Disease Classification", | |
| description="Upload an image of skin disease to classify it." | |
| ) | |
| # Launch the interface | |
| iface.launch() | |