Spaces:
Sleeping
Sleeping
File size: 1,142 Bytes
0fb0a1e 8aee766 0ea79dc 0fb0a1e 8aee766 0fb0a1e cbf8496 436622b 8aee766 0fb0a1e 436622b 0fb0a1e 8aee766 0fb0a1e 436622b 0fb0a1e 8aee766 0fb0a1e cbf8496 0fb0a1e 436622b 0fb0a1e | 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 | import gradio as gr
import numpy as np
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.image import img_to_array
from PIL import Image
model = load_model("scalp_mobilenetv2_model.h5")
# Update class labels based on your training class_indices
class_labels = ['dry', 'healthy', 'oily'] # <-- Double-check this order
def preprocess_image(image):
image = image.resize((128, 128))
image = img_to_array(image) / 255.0
image = np.expand_dims(image, axis=0)
return image
def predict_scalp(image):
processed_image = preprocess_image(image)
prediction = model.predict(processed_image)
print("Raw prediction:", prediction[0]) # <-- Debug
class_index = np.argmax(prediction[0])
confidence = float(np.max(prediction[0]))
return {class_labels[class_index]: confidence}
interface = gr.Interface(
fn=predict_scalp,
inputs=gr.Image(type="pil"),
outputs=gr.Label(num_top_classes=3),
title="Scalp Condition Classifier",
description="Upload a scalp image (128x128+). Model predicts dry, healthy, or oily."
)
if __name__ == "__main__":
interface.launch()
|