Spaces:
Sleeping
Sleeping
Create app.py file
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
from tensorflow.keras.applications import imagenet_utils
|
4 |
+
from tensorflow.keras.utils import img_to_array
|
5 |
+
from tensorflow.keras.models import load_model
|
6 |
+
import numpy as np
|
7 |
+
import cv2
|
8 |
+
import pickle
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
def Prediction_VGG16(image):
|
15 |
+
|
16 |
+
#Prepare image
|
17 |
+
IMG_SIZE = 224
|
18 |
+
image = img_to_array(image)
|
19 |
+
image = image**1.0/255.0
|
20 |
+
img_prepared = image.reshape((-1,IMG_SIZE,IMG_SIZE,3))
|
21 |
+
print(img_prepared)
|
22 |
+
|
23 |
+
#Load model vgg6 package
|
24 |
+
path = ".\model\model_vgg16.h5"
|
25 |
+
my_model =load_model(path)
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
#Prediction
|
30 |
+
classes = ["Brain Tumor","Healthy"]
|
31 |
+
prediction = my_model.predict(img_prepared)[0]
|
32 |
+
prediction = prediction.tolist()
|
33 |
+
|
34 |
+
|
35 |
+
return {k:v for k,v in zip(classes,prediction)}
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
demo = gr.Interface(Prediction_VGG16, gr.inputs.Image(shape=(224,224)),gr.Label(num_top_classes=2))
|
41 |
+
|
42 |
+
demo.launch()
|