Created
May 17, 2024 20:07
-
-
Save idontcalculate/15e5e5a61653310b1e3ee04a662dd088 to your computer and use it in GitHub Desktop.
gradio wrapper around predictions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
from tensorflow.keras.models import load_model | |
import gradio as gr | |
import numpy as np | |
from PIL import Image | |
# Load the saved model | |
model = load_model("modelVGG16.h5") | |
# Define the prediction function | |
def predict_bone_fracture(img): | |
img = img.resize((256, 256)) | |
img = np.array(img) / 255.0 | |
img = np.expand_dims(img, axis=0) | |
prediction = model.predict(img)[0][0] | |
return "Broken" if prediction > 0.5 else "Not Broken" | |
# Create Gradio interface | |
interface = gr.Interface( | |
fn=predict_bone_fracture, | |
inputs=gr.inputs.Image(type="pil"), | |
outputs="text", | |
title="Bone Fracture Detection", | |
description="Upload an X-ray image to check if there is a bone fracture." | |
) | |
# Launch the Gradio app | |
interface.launch() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment