Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from tensorflow.keras.models import load_model
|
| 3 |
+
from tensorflow.keras.preprocessing import image
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# Load the trained model
|
| 7 |
+
model = load_model("best_model.keras")
|
| 8 |
+
|
| 9 |
+
# Define disease labels
|
| 10 |
+
disease_labels = [
|
| 11 |
+
"Cellulitis", "Impetigo", "Athlete's Foot", "Nail Fungus",
|
| 12 |
+
"Ringworm", "Cutaneous Larva Migrans", "Chickenpox", "Shingles"
|
| 13 |
+
]
|
| 14 |
+
|
| 15 |
+
# Define the prediction function
|
| 16 |
+
def predict_disease(img):
|
| 17 |
+
# Preprocess the image
|
| 18 |
+
img = img.resize((224, 224))
|
| 19 |
+
img_array = image.img_to_array(img)
|
| 20 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 21 |
+
img_array /= 255.0 # Normalize to [0, 1] range
|
| 22 |
+
|
| 23 |
+
# Make prediction
|
| 24 |
+
predictions = model.predict(img_array)
|
| 25 |
+
predicted_index = np.argmax(predictions)
|
| 26 |
+
|
| 27 |
+
# Return the predicted disease
|
| 28 |
+
return disease_labels[predicted_index]
|
| 29 |
+
|
| 30 |
+
# Create Gradio interface
|
| 31 |
+
iface = gr.Interface(
|
| 32 |
+
fn=predict_disease,
|
| 33 |
+
inputs=gr.inputs.Image(type="pil"),
|
| 34 |
+
outputs="text",
|
| 35 |
+
title="Skin Disease Classification",
|
| 36 |
+
description="Upload an image of skin disease to classify it."
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
# Launch the interface
|
| 40 |
+
iface.launch()
|
| 41 |
+
|