File size: 1,467 Bytes
b44c4e5
26eaf37
 
 
 
 
 
 
 
 
 
 
 
00c3ab6
26eaf37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import torch
from PIL import Image
from modelOps import load_model, preprocess_image, predict_class

def main():
    st.set_page_config(page_title="Breaking Bone", page_icon="🦴")
    st.title("🦴 Breaking Bone")
    st.write("An X-Ray Broken Bone Classifier")
    st.caption("Prepared by: John Manuel Carado")
    st.write("Upload an X-ray image to classify potential fractures.")

    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
    model = load_model(device=device)

    uploaded_file = st.file_uploader("Upload an X-ray image", type=["jpg", "jpeg", "png"])

    if uploaded_file:
        image = Image.open(uploaded_file).convert("RGB")

        col1, col2 = st.columns(2)

        with col1:
            st.image(image, caption="Uploaded Image")

        with col2:
            st.subheader("Classification Results")
            with st.spinner("Classifying..."):
                try:
                    input_tensor = preprocess_image(image).to(device)
                    pred, conf = predict_class(input_tensor, model)
                    st.success(f"Predicted Class: **{pred}**")
                    st.info(f"Confidence: **{conf:.2%}**")
                except Exception as e:
                    st.error(f"An error occurred during classification: {e}")
                    st.write("Please ensure the uploaded image is valid and the model is loaded correctly.")

if __name__ == "__main__":
    main()