Spaces:
Sleeping
Sleeping
Rename app (2).py to app.py
Browse files- app (2).py +0 -36
- app.py +22 -0
app (2).py
DELETED
|
@@ -1,36 +0,0 @@
|
|
| 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')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import cv2
|
| 4 |
+
import numpy as np
|
| 5 |
+
from ultralytics import YOLO
|
| 6 |
+
|
| 7 |
+
model = YOLO('best (6).pt')
|
| 8 |
+
|
| 9 |
+
def predict_image(img):
|
| 10 |
+
|
| 11 |
+
model = YOLO('best (6).pt')
|
| 12 |
+
result = model.predict(img)
|
| 13 |
+
res_plotted = result[0].plot()
|
| 14 |
+
#cv2.imshow( res_plotted)
|
| 15 |
+
return res_plotted
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
image = gr.inputs.Image()
|
| 20 |
+
|
| 21 |
+
label = gr.outputs.Label('ok')
|
| 22 |
+
gr.Interface(fn=predict_image, inputs=image, outputs=image).launch(debug='True')
|