Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import cv2
|
| 6 |
+
|
| 7 |
+
# Load model
|
| 8 |
+
model = tf.keras.models.load_model("model/model.h5")
|
| 9 |
+
|
| 10 |
+
def preprocess_image(image):
|
| 11 |
+
image = np.array(image)
|
| 12 |
+
image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
|
| 13 |
+
image = cv2.resize(image, (224, 224))
|
| 14 |
+
image = image / 255.0
|
| 15 |
+
image = image.reshape(1, 224, 224, 1)
|
| 16 |
+
return image
|
| 17 |
+
|
| 18 |
+
def predict(image):
|
| 19 |
+
image = preprocess_image(image)
|
| 20 |
+
prediction = model.predict(image)[0][0]
|
| 21 |
+
|
| 22 |
+
if prediction > 0.5:
|
| 23 |
+
return {"Fractured": float(prediction), "Normal": float(1 - prediction)}
|
| 24 |
+
else:
|
| 25 |
+
return {"Normal": float(1 - prediction), "Fractured": float(prediction)}
|
| 26 |
+
|
| 27 |
+
gr.Interface(
|
| 28 |
+
fn=predict,
|
| 29 |
+
inputs=gr.Image(type="pil"),
|
| 30 |
+
outputs=gr.Label(num_top_classes=2),
|
| 31 |
+
title="Bone Fracture Detection",
|
| 32 |
+
description="Upload an X-ray image to detect bone fracture"
|
| 33 |
+
).launch()
|