Spaces:
Runtime error
Runtime error
Upload app (2).py
Browse files- app (2).py +36 -0
app (2).py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
import tensorflow as tf
|
4 |
+
import tensorflow.keras
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
import cv2
|
7 |
+
import tensorflow_io as tfio
|
8 |
+
import numpy as np
|
9 |
+
|
10 |
+
loaded_model = tf.keras.models.load_model( 'brain1.h5')
|
11 |
+
|
12 |
+
def take_img(img):
|
13 |
+
|
14 |
+
resize = tf.image.resize(img, (128,128))
|
15 |
+
gray = tfio.experimental.color.bgr_to_rgb(resize)
|
16 |
+
yhat = loaded_model.predict(np.expand_dims(gray/255, 0))
|
17 |
+
label_names = {
|
18 |
+
"1": "Tumor",
|
19 |
+
"2": "Normal"}
|
20 |
+
classes_x=np.argmax(yhat,axis=1)
|
21 |
+
a = classes_x[0]
|
22 |
+
input_value = a + 1
|
23 |
+
input_str = str(input_value)
|
24 |
+
predicted_label = label_names[input_str]
|
25 |
+
tumor = yhat[0][0]
|
26 |
+
tumor = str(tumor)
|
27 |
+
normal = yhat[0][1]
|
28 |
+
normal = str(normal)
|
29 |
+
return {'Tumour': tumor, 'Normal':normal}
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
image = gr.inputs.Image(shape=(128,128))
|
34 |
+
|
35 |
+
label = gr.outputs.Label('ok')
|
36 |
+
gr.Interface(fn=take_img, inputs=image, outputs="label",interpretation='default').launch(debug='True')
|