Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import tensorflow as tf | |
| import numpy as np | |
| from PIL import Image | |
| CLASS_NAMES = ["Oral Homogenous Leukoplakia", "Oral Non-Homogenous Leukoplakia", "Other Oral White Lesions"] | |
| model = tf.keras.models.load_model('./model.keras') | |
| def predict(image): | |
| img = image.convert("RGB").resize((224, 224)) | |
| arr = (np.array(img, dtype=np.float32) / 127.5) - 1.0 | |
| preds = model.predict(np.expand_dims(arr, 0))[0] | |
| idx = int(np.argmax(preds)) | |
| return {"className": CLASS_NAMES[idx], "confidence": round(float(preds[idx]) * 100, 1)} | |
| demo = gr.Interface(fn=predict, inputs=gr.Image(type="pil"), outputs="json") | |
| demo.launch() | |