Harshini Murali commited on
Commit
7fc3dec
·
verified ·
1 Parent(s): e57ddf0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ from PIL import Image
4
+ import numpy as np
5
+
6
+ # Load model
7
+ model = tf.keras.models.load_model("oa.keras")
8
+
9
+ # Define class labels
10
+ class_labels = ['Healthy', 'Moderate', 'Severe']
11
+
12
+ # Page title
13
+ st.title("Knee Osteoarthritis Severity Classifier")
14
+
15
+ # File uploader
16
+ uploaded_file = st.file_uploader("Upload a Knee X-ray Image", type=["jpg", "jpeg", "png"])
17
+
18
+ if uploaded_file:
19
+ # Show uploaded image
20
+ image = Image.open(uploaded_file)
21
+ st.image(image, caption='Uploaded Image', use_column_width=True)
22
+
23
+ # Preprocess the image
24
+ img = image.resize((224, 224))
25
+ img_array = np.array(img)
26
+ if img_array.shape[-1] == 4: # if RGBA, convert to RGB
27
+ img_array = img_array[:, :, :3]
28
+ img_array = img_array / 255.0
29
+ img_array = np.expand_dims(img_array, axis=0)
30
+
31
+ # Predict
32
+ prediction = model.predict(img_array)
33
+ predicted_class = class_labels[np.argmax(prediction)]
34
+ confidence = np.max(prediction)
35
+
36
+ # Show result
37
+ st.markdown(f"### 🩺 Predicted Class: **{predicted_class}**")
38
+ st.markdown(f"Confidence: `{confidence:.2f}`")