Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import tensorflow as tf
|
|
3 |
import numpy as np
|
4 |
from tensorflow.keras.preprocessing import image
|
5 |
from PIL import Image
|
|
|
6 |
|
7 |
# Load the trained model
|
8 |
model = tf.keras.models.load_model("my_keras_model.h5")
|
@@ -23,13 +24,9 @@ def predict_image(img):
|
|
23 |
|
24 |
return f"Prediction: {predicted_class} (Confidence: {prediction[0][0]:.2f})"
|
25 |
|
26 |
-
#
|
27 |
-
|
28 |
-
|
29 |
-
("fracture2.jpg", "Fractured Example"),
|
30 |
-
("normal1.jpg", "Normal Example"),
|
31 |
-
("normal2.jpg", "Normal Example"),
|
32 |
-
]
|
33 |
|
34 |
# Define Gradio Interface
|
35 |
interface = gr.Interface(
|
@@ -38,11 +35,7 @@ interface = gr.Interface(
|
|
38 |
outputs=gr.Textbox(),
|
39 |
examples=sample_images, # Preloaded images for testing
|
40 |
title="Bone Fracture Detection",
|
41 |
-
description=""
|
42 |
-
<h1 style='color: blue;'>Bone Fracture Detection Model</h1>
|
43 |
-
<p>This AI model predicts whether a given X-ray image shows a fracture or not.</p>
|
44 |
-
<p><b>Upload an image</b> or select from the provided samples to get a prediction.</p>
|
45 |
-
""",
|
46 |
)
|
47 |
|
48 |
# Launch the Gradio app
|
|
|
3 |
import numpy as np
|
4 |
from tensorflow.keras.preprocessing import image
|
5 |
from PIL import Image
|
6 |
+
import os
|
7 |
|
8 |
# Load the trained model
|
9 |
model = tf.keras.models.load_model("my_keras_model.h5")
|
|
|
24 |
|
25 |
return f"Prediction: {predicted_class} (Confidence: {prediction[0][0]:.2f})"
|
26 |
|
27 |
+
# Get image paths dynamically
|
28 |
+
sample_images_dir = "samples"
|
29 |
+
sample_images = [os.path.join(sample_images_dir, f) for f in os.listdir(sample_images_dir) if f.endswith(('.jpg', '.png'))]
|
|
|
|
|
|
|
|
|
30 |
|
31 |
# Define Gradio Interface
|
32 |
interface = gr.Interface(
|
|
|
35 |
outputs=gr.Textbox(),
|
36 |
examples=sample_images, # Preloaded images for testing
|
37 |
title="Bone Fracture Detection",
|
38 |
+
description="Upload an X-ray image or select a sample image to check for fractures."
|
|
|
|
|
|
|
|
|
39 |
)
|
40 |
|
41 |
# Launch the Gradio app
|