fracture / app.py
kris524's picture
Create app.py
acac8bc verified
raw
history blame contribute delete
915 Bytes
import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image
import cv2
# Load model
model = tf.keras.models.load_model("model/model.h5")
def preprocess_image(image):
image = np.array(image)
image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
image = cv2.resize(image, (224, 224))
image = image / 255.0
image = image.reshape(1, 224, 224, 1)
return image
def predict(image):
image = preprocess_image(image)
prediction = model.predict(image)[0][0]
if prediction > 0.5:
return {"Fractured": float(prediction), "Normal": float(1 - prediction)}
else:
return {"Normal": float(1 - prediction), "Fractured": float(prediction)}
gr.Interface(
fn=predict,
inputs=gr.Image(type="pil"),
outputs=gr.Label(num_top_classes=2),
title="Bone Fracture Detection",
description="Upload an X-ray image to detect bone fracture"
).launch()