Spaces:
Runtime error
Runtime error
this new update code of app.py
Browse files- New Text Document.txt +34 -0
New Text Document.txt
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
os.system("pip install tensorflow gradio numpy pillow") # Install required packages
|
| 3 |
+
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import tensorflow as tf
|
| 6 |
+
import numpy as np
|
| 7 |
+
from tensorflow.keras.preprocessing import image
|
| 8 |
+
|
| 9 |
+
# Load the trained model
|
| 10 |
+
model = tf.keras.models.load_model("bone_xray_cnn_model.h5")
|
| 11 |
+
|
| 12 |
+
# Prediction function
|
| 13 |
+
def predict_bone_xray(img):
|
| 14 |
+
img = img.resize((224, 224)) # Resize image
|
| 15 |
+
img_array = image.img_to_array(img) / 255.0 # Normalize
|
| 16 |
+
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
|
| 17 |
+
|
| 18 |
+
prediction = np.argmax(model.predict(img_array))
|
| 19 |
+
|
| 20 |
+
if prediction == 0:
|
| 21 |
+
return "Fractured Bone"
|
| 22 |
+
else:
|
| 23 |
+
return "Healthy Bone"
|
| 24 |
+
|
| 25 |
+
# Create Gradio interface
|
| 26 |
+
interface = gr.Interface(
|
| 27 |
+
fn=predict_bone_xray,
|
| 28 |
+
inputs=gr.Image(type="pil"),
|
| 29 |
+
outputs="text",
|
| 30 |
+
title="Bone X-ray Classifier",
|
| 31 |
+
description="Upload an X-ray image to detect bone fractures."
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
interface.launch()
|