Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
CLASS_NAMES = ["Oral Homogenous Leukoplakia", "Oral Non-Homogenous Leukoplakia", "Other Oral White Lesions"]
|
| 7 |
+
model = tf.keras.models.load_model('./model.keras')
|
| 8 |
+
|
| 9 |
+
def predict(image):
|
| 10 |
+
img = image.convert("RGB").resize((224, 224))
|
| 11 |
+
arr = (np.array(img, dtype=np.float32) / 127.5) - 1.0
|
| 12 |
+
preds = model.predict(np.expand_dims(arr, 0))[0]
|
| 13 |
+
idx = int(np.argmax(preds))
|
| 14 |
+
return {"className": CLASS_NAMES[idx], "confidence": round(float(preds[idx]) * 100, 1)}
|
| 15 |
+
|
| 16 |
+
demo = gr.Interface(fn=predict, inputs=gr.Image(type="pil"), outputs="json")
|
| 17 |
+
demo.launch()
|