NerdyAlgorithm commited on
Commit
f45506b
·
verified ·
1 Parent(s): ad16bb6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -0
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()