danishjaved commited on
Commit
6b2215e
1 Parent(s): fd0b5f7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from tensorflow.keras.preprocessing import image
3
+ import gradio as gr
4
+ import numpy as np
5
+ from tensorflow.keras.preprocessing import image
6
+ import gradio as gr
7
+ import keras
8
+
9
+ model = keras.models.load_model('x_ray.keras')
10
+
11
+ # Define the function for image classification
12
+ def classify_image(img):
13
+ # Set the input image dimensions
14
+ img_width, img_height = 150, 150
15
+
16
+ # Resize the image to match the model's input shape
17
+ img = img.resize((img_width, img_height))
18
+
19
+ # Convert the image to a numpy array
20
+ img = np.array(img)
21
+ img = img.astype('float32') / 255.0
22
+ img = np.expand_dims(img, axis=0)
23
+
24
+ # Get the prediction
25
+ prediction = model.predict(img)
26
+
27
+ return "NOT fractured" if prediction > 0.5 else "fractured"
28
+
29
+ # Create a Gradio interface
30
+ iface = gr.Interface(
31
+ fn=classify_image,
32
+ inputs=gr.inputs.Image(type="pil", label="Upload an X-ray image"),
33
+ outputs="text",
34
+ title="Bone Fracture Classification",
35
+ description="Upload an X-ray image, and this model will classify it as fractured or not.",
36
+ )
37
+
38
+ # Start the Gradio interface
39
+ iface.launch()