ajaydannur commited on
Commit
a779215
·
verified ·
1 Parent(s): 4186eea

change the code

Browse files
Files changed (1) hide show
  1. app.py +34 -31
app.py CHANGED
@@ -1,31 +1,34 @@
1
- import gradio as gr
2
- import tensorflow as tf
3
- import numpy as np
4
- from tensorflow.keras.preprocessing import image
5
-
6
- # Load the trained model
7
- model = tf.keras.models.load_model("bone_xray_cnn_model.h5")
8
-
9
- # Function to predict
10
- def predict_bone_xray(img):
11
- img = img.resize((224, 224)) # Resize image
12
- img_array = image.img_to_array(img) / 255.0 # Normalize
13
- img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
14
-
15
- prediction = np.argmax(model.predict(img_array))
16
-
17
- if prediction == 0:
18
- return "Fractured Bone"
19
- else:
20
- return "Healthy Bone"
21
-
22
- # Create Gradio interface
23
- interface = gr.Interface(
24
- fn=predict_bone_xray,
25
- inputs=gr.Image(type="pil"),
26
- outputs="text",
27
- title="Bone X-ray Classifier",
28
- description="Upload an X-ray image to detect bone fractures."
29
- )
30
-
31
- interface.launch()
 
 
 
 
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()