Venisri2006's picture
Update app.py
12cced4 verified
import os
from PIL import Image
import requests
import gradio as gr
import tensorflow as tf
import numpy as np
# Download the model at runtime
MODEL_URL = "https://huggingface.co/Venisri2006/psoriasis-severity-classifier/resolve/main/psoriasis_classifier.keras"
MODEL_PATH = "updated_model.keras"
# Download the model if it does not exist
if not os.path.exists(MODEL_PATH):
print("Downloading model...")
r = requests.get(MODEL_URL, allow_redirects=True)
open(MODEL_PATH, "wb").write(r.content)
# Load model
model = tf.keras.models.load_model(MODEL_PATH)
# Define classes
classes = ["Mild", "Moderate", "Severe"]
def predict_psoriasis(image):
image = image.resize((224, 224)) # Resize to model input size
image = np.array(image) / 255.0 # Normalize
image = np.expand_dims(image, axis=0) # Add batch dimension
prediction = model.predict(image)[0]
severity = classes[np.argmax(prediction)]
return {"Severity": severity, "Confidence": float(np.max(prediction))}
# Create Gradio interface
iface = gr.Interface(
fn=predict_psoriasis,
inputs=gr.Image(type="pil"),
outputs=gr.Label(),
title="Psoriasis Severity Classifier",
description="Upload an image of skin affected by psoriasis to predict severity (Mild, Moderate, Severe)."
)
iface.launch()