Spaces:
Sleeping
Sleeping
Initial commit
Browse files- app.py +35 -0
- cnn.tflite +3 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
interpreter = tf.lite.Interpreter(model_path = "cnn.tflite")
|
7 |
+
interpreter.allocate_tensors()
|
8 |
+
input_details = interpreter.get_input_details()
|
9 |
+
output_details = interpreter.get_output_details()
|
10 |
+
|
11 |
+
CLASSES = ["Glioma", "Meningioma", "No Tumor", "Pituitary"]
|
12 |
+
IMG_SIZE = (224, 224)
|
13 |
+
|
14 |
+
def preprocess(img: Image.Image) -> np.ndarray:
|
15 |
+
img = img.resize(IMG_SIZE)
|
16 |
+
arr = np.asarray(img, dtype=np.float32) / 255.0
|
17 |
+
return np.expand_dims(arr, 0)
|
18 |
+
|
19 |
+
def predict(image):
|
20 |
+
x = preprocess(image)
|
21 |
+
interpreter.set_tensor(input_details[0]["index"], x)
|
22 |
+
interpreter.invoke()
|
23 |
+
probs = interpreter.get_tensor(output_details[0]["index"])
|
24 |
+
return CLASSES[int(np.argmax(probs, axis=1)[0])]
|
25 |
+
|
26 |
+
demo = gr.Interface(
|
27 |
+
fn=predict,
|
28 |
+
inputs=gr.Image(type="pil", label="Brain MRI"),
|
29 |
+
outputs=gr.Label(num_top_classes=4),
|
30 |
+
title="Brain‑Tumor Classifier (.tflite)",
|
31 |
+
description="Returns: Glioma, Meningioma, No Tumor, Pituitary"
|
32 |
+
)
|
33 |
+
|
34 |
+
if __name__ == "__main__":
|
35 |
+
demo.launch()
|
cnn.tflite
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d621e23d2e705ed9a44696e02be7d93d312ba6ed3e21360e3795973cde31fb49
|
3 |
+
size 51427444
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow==2.15.0
|
2 |
+
gradio>=4.31,<5
|
3 |
+
pillow
|
4 |
+
numpy
|