danishjaved's picture
Create app.py
6b2215e
raw
history blame contribute delete
No virus
1.11 kB
import numpy as np
from tensorflow.keras.preprocessing import image
import gradio as gr
import numpy as np
from tensorflow.keras.preprocessing import image
import gradio as gr
import keras
model = keras.models.load_model('x_ray.keras')
# Define the function for image classification
def classify_image(img):
# Set the input image dimensions
img_width, img_height = 150, 150
# Resize the image to match the model's input shape
img = img.resize((img_width, img_height))
# Convert the image to a numpy array
img = np.array(img)
img = img.astype('float32') / 255.0
img = np.expand_dims(img, axis=0)
# Get the prediction
prediction = model.predict(img)
return "NOT fractured" if prediction > 0.5 else "fractured"
# Create a Gradio interface
iface = gr.Interface(
fn=classify_image,
inputs=gr.inputs.Image(type="pil", label="Upload an X-ray image"),
outputs="text",
title="Bone Fracture Classification",
description="Upload an X-ray image, and this model will classify it as fractured or not.",
)
# Start the Gradio interface
iface.launch()