test
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from tensorflow.keras.models import load_model
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
model = load_model('xray_image_classifier_model.keras')
|
7 |
+
|
8 |
+
def predict_image(img):
|
9 |
+
img = img.resize((150, 150))
|
10 |
+
img = np.array(img) / 255.0
|
11 |
+
img = np.expand_dims(img, axis=0)
|
12 |
+
prediction = model.predict(img)
|
13 |
+
label = 'Pneumonia' if prediction > 0.5 else 'Normal'
|
14 |
+
return label
|
15 |
+
|
16 |
+
iface = gr.Interface(
|
17 |
+
fn=predict_image,
|
18 |
+
inputs=gr.inputs.Image(type="pil"),
|
19 |
+
outputs="text",
|
20 |
+
title="X-ray Image Classifier",
|
21 |
+
description="Upload an X-ray image to classify it as 'Pneumonia' or 'Normal'."
|
22 |
+
)
|
23 |
+
|
24 |
+
iface.launch()
|