File size: 1,601 Bytes
7fc3dec
 
02c7efd
 
 
 
 
 
 
 
 
 
 
 
 
 
7fc3dec
 
02c7efd
 
 
 
 
 
7fc3dec
 
 
 
02c7efd
 
7fc3dec
02c7efd
 
 
 
7fc3dec
02c7efd
7fc3dec
02c7efd
 
 
 
 
 
 
7fc3dec
 
02c7efd
 
 
 
 
 
 
 
7fc3dec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import streamlit as st
import numpy as np
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
from PIL import Image

# Set page config
st.set_page_config(
    page_title="Knee Osteoarthritis Classifier",
    layout="centered",
    initial_sidebar_state="auto"
)

# Title
st.title("🔍 Knee Osteoarthritis Severity Classifier")
st.markdown("Upload a **knee X-ray** image to predict the severity level: **Healthy**, **Moderate**, or **Severe**.")

# Load model
@st.cache_resource
def load_effnet_model():
    model = load_model("efficientnetb3_knee_oa.keras")
    return model

model = load_effnet_model()

# Define class labels
class_labels = ['Healthy', 'Moderate', 'Severe']

# Image uploader
uploaded_file = st.file_uploader("📤 Upload an X-ray image (PNG/JPG)", type=["jpg", "jpeg", "png"])

# Or show default image
if uploaded_file is None:
    st.info("No image uploaded. Displaying a default sample image.")
    uploaded_file = "sample_image.png"

# Prediction and result
if uploaded_file:
    img = Image.open(uploaded_file).convert("RGB")
    st.image(img, caption="Uploaded Image", use_column_width=True)

    # Preprocess image
    img_resized = img.resize((224, 224))
    img_array = image.img_to_array(img_resized)
    img_array = np.expand_dims(img_array, axis=0) / 255.0

    # Predict
    preds = model.predict(img_array)
    predicted_class = class_labels[np.argmax(preds)]
    confidence = np.max(preds)

    # Output
    st.subheader("🔬 Prediction:")
    st.success(f"**{predicted_class}** with {confidence*100:.2f}% confidence.")