DHEIVER commited on
Commit
cab105c
1 Parent(s): 7d93a92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -41
app.py CHANGED
@@ -1,45 +1,31 @@
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( 'kidney2.h5')
11
-
12
- def take_img(img):
13
-
14
- resize = tf.image.resize(img, (224,224))
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": "Cyst",
19
- "2": "Normal",
20
- "3": "Stone",
21
- "4": "Tumor"
22
- }
23
- classes_x=np.argmax(yhat,axis=1)
24
- a = classes_x[0]
25
- input_value = a + 1
26
- input_str = str(input_value)
27
- predicted_label = label_names[input_str]
28
- q= yhat[0][0]
29
- w = yhat[0][1]
30
- e = yhat[0][2]
31
- r = yhat[0][3]
32
-
33
- q = str(q)
34
- w = str(w)
35
- e = str(e)
36
- r = str(r)
37
-
38
- return {'cryst' : q ,'Normal' : w ,'Stone' : e ,'Tumour' : r }
39
-
40
-
41
-
42
- image = gr.inputs.Image(shape=(224,224))
43
-
44
- label = gr.outputs.Label('ok')
45
- gr.Interface(fn=take_img, inputs=image, outputs="label",interpretation='default').launch(debug='True')
 
 
1
  import gradio as gr
2
+ import tensorflow as tf
 
 
 
3
  import tensorflow_io as tfio
4
  import numpy as np
5
 
6
+ loaded_model = tf.keras.models.load_model('kidney2.h5')
7
+
8
+ def classify_kidney_image(img):
9
+ resize = tf.image.resize(img, (224, 224))
10
+ gray = tfio.experimental.color.bgr_to_rgb(resize)
11
+ yhat = loaded_model.predict(np.expand_dims(gray / 255, 0))
12
+ label_names = {
13
+ "1": "Cyst",
14
+ "2": "Normal",
15
+ "3": "Stone",
16
+ "4": "Tumor"
17
+ }
18
+ classes_x = np.argmax(yhat, axis=1)
19
+ a = classes_x[0]
20
+ input_value = a + 1
21
+ input_str = str(input_value)
22
+ predicted_label = label_names[input_str]
23
+ q, w, e, r = yhat[0]
24
+
25
+ return {'Cyst': str(q), 'Normal': str(w), 'Stone': str(e), 'Tumor': str(r)}
26
+
27
+ image = gr.inputs.Image(shape=(224, 224))
28
+ label = gr.outputs.Label()
29
+
30
+ app = gr.Interface(fn=classify_kidney_image, inputs=image, outputs=label, interpretation='default', title='Kidney Image Classifier')
31
+ app.launch(debug=True)