File size: 2,177 Bytes
9393c29
 
 
 
 
 
 
 
 
 
 
3a1b60a
9393c29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6520d7c
9393c29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6520d7c
 
 
cf3b43c
 
 
 
 
 
 
 
 
 
6520d7c
 
9393c29
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import gradio as gr
import numpy as np
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
from PIL import Image
# Fixed image URL
fixed_image_url = "222.PNG"

# Example images and their descriptions
examples = [
    ["Avulsion fracture.jpg", "Avulsion fracture."]
]
# Load your trained model
model = load_model("bone_break_classification_model.h5")

# Define your class names dictionary
class_names_dict = {
    0: 'Avulsion fracture',
    1: 'Comminuted fracture',
    2: 'Fracture Dislocation',
    3: 'Greenstick fracture',
    4: 'Hairline Fracture',
    5: 'Imapacted fracture',
    6: 'Longitudinal fracture',
    7: 'Oblique fracture',
    8: 'Pathological fracture',
    9: 'Spiral Fracture'
}


def predict_image(img_path):
    # Load the image using PIL
    img = Image.open(img_path)
    img = img.resize((256, 256))  # Resize the image
    img_array = np.array(img) / 255.0  # Normalize
    img_array = np.expand_dims(img_array, axis=0)  # Add batch dimension

    # Make prediction
    prediction = model.predict(img_array)
    predicted_class_index = np.argmax(prediction, axis=-1)[0]
    predicted_class_name = class_names_dict.get(predicted_class_index, "Unknown Class")

    return predicted_class_name ,fixed_image_url

# Create Gradio interface
iface = gr.Interface(
    fn=predict_image,
    inputs=gr.Image(type="filepath", label="Upload an Image"),
    outputs=[
        gr.Textbox(label="Prediction"),
        gr.Image(label=" Bone Fracture Detection ", value=fixed_image_url)  
    ],
    title="Bone Break Classification",
    description=(
        "Upload an X-ray image, and the model will predict the type of bone break. \n\n"
        "Classes Available:\n"
        "Avulsion fracture\n"
        "Comminuted fracture\n"
        "Fracture Dislocation\n"
        "Greenstick fracture\n"
        "Hairline Fracture\n"
        "Impacted fracture\n"
        "Longitudinal fracture\n"
        "Oblique fracture\n"
        "Pathological fracture\n"
        "Spiral Fracture"
    ),
                ,
    theme="ParityError/Interstellar",
    examples=examples,
)

# Launch the interface
iface.launch(debug=True)