Update app.py
Browse files
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 |
-
|
|
|
|
| 8 |
|
|
|
|
| 9 |
LABELS = ['NORMAL', 'TUBERCULOSIS', 'PNEUMONIA', 'COVID19']
|
| 10 |
|
|
|
|
| 11 |
def predict_input_image(img):
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
with gr.
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 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()
|
|
|