Nurisslam commited on
Commit
8ada2ca
·
verified ·
1 Parent(s): 824b51e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -31
app.py CHANGED
@@ -1,39 +1,39 @@
1
  import gradio as gr
2
-
3
  import tensorflow as tf
4
- import os
5
  import numpy as np
6
 
7
- model = tf.keras.models.load_model('model.hdf5',compile=False)
 
8
 
 
9
  LABELS = ['NORMAL', 'TUBERCULOSIS', 'PNEUMONIA', 'COVID19']
10
 
 
11
  def predict_input_image(img):
12
- img_4d=img.reshape(-1,128,128,3)/255.0
13
- print(img_4d.min())
14
- print(img_4d.max())
15
- prediction=model.predict(img_4d)[0]
16
- return {LABELS[i]: float(prediction[i]) for i in range(4)}
17
-
18
- def k():
19
- return gr.update(value=None)
20
-
21
- with gr.Blocks(title="Lung Disease Classification", css="") as demo:
22
- with gr.Row():
23
- textmd = gr.Markdown()
24
- with gr.Row():
25
- with gr.Column(scale=1, min_width=600):
26
- image = gr.inputs.Image(shape=(128,128))
27
- with gr.Row():
28
- clear_btn = gr.Button("Clear")
29
- submit_btn = gr.Button("Submit", elem_id="warningk", variant='primary')
30
- '''examples = gr.Examples(examples=["COVID19-0.jpg",
31
- "NORMAL-0.jpeg",
32
- "COVID19-1.jpg",
33
- "PNEUMONIA-0.jpeg"], inputs=image)'''
34
- label = gr.outputs.Label(num_top_classes=4)
35
-
36
- clear_btn.click(k, inputs=[], outputs=image)
37
- submit_btn.click(predict_input_image, inputs=image, outputs=label)
38
-
39
- demo.launch()
 
1
  import gradio as gr
 
2
  import tensorflow as tf
 
3
  import numpy as np
4
 
5
+ # Модельді жүктеу
6
+ model = tf.keras.models.load_model('model.hdf5', compile=False)
7
 
8
+ # Класстар тізімі
9
  LABELS = ['NORMAL', 'TUBERCULOSIS', 'PNEUMONIA', 'COVID19']
10
 
11
+ # Суретті өңдеу және болжау функциясы
12
  def predict_input_image(img):
13
+ img = img.resize((128, 128))
14
+ img_array = np.array(img).reshape(-1, 128, 128, 3) / 255.0
15
+ prediction = model.predict(img_array)[0]
16
+ return {LABELS[i]: float(prediction[i]) for i in range(4)}
17
+
18
+ # Clear функциясы
19
+ def clear_image():
20
+ return None
21
+
22
+ # Интерфейс құру
23
+ with gr.Blocks(title="Lung Disease Classification") as demo:
24
+ gr.Markdown("## Lung Disease Classification Model\nUpload a chest X-ray to predict disease class.")
25
+
26
+ with gr.Row():
27
+ with gr.Column(scale=1, min_width=600):
28
+ image = gr.Image(type="pil", shape=(128, 128), label="Upload image")
29
+ with gr.Row():
30
+ clear_btn = gr.Button("Clear")
31
+ submit_btn = gr.Button("Submit", variant='primary')
32
+ label = gr.Label(num_top_classes=4)
33
+
34
+ # Батырмаларға функцияларды бекіту
35
+ clear_btn.click(fn=clear_image, inputs=[], outputs=image)
36
+ submit_btn.click(fn=predict_input_image, inputs=image, outputs=label)
37
+
38
+ # Интерфейсті іске қосу
39
+ demo.launch()