|
import streamlit as st |
|
import pickle |
|
from PIL import Image |
|
|
|
|
|
model_filename = 'model.pkl' |
|
with open(model_filename, 'rb') as file: |
|
model = pickle.load(file) |
|
|
|
|
|
def predict_pneumonia(image): |
|
|
|
|
|
|
|
|
|
prediction = model.predict(image) |
|
|
|
return prediction |
|
|
|
|
|
def main(): |
|
|
|
st.title("Pneumonia Detection") |
|
st.markdown("---") |
|
|
|
|
|
st.header("Upload Chest X-ray Image") |
|
uploaded_file = st.file_uploader("Choose an image", type=["jpg", "jpeg", "png"]) |
|
|
|
if uploaded_file is not None: |
|
|
|
image = Image.open(uploaded_file) |
|
st.image(image, caption="Uploaded Image", use_column_width=True) |
|
|
|
|
|
if st.button("Predict"): |
|
|
|
prediction = predict_pneumonia(image) |
|
|
|
|
|
if prediction == 1: |
|
st.error("Prediction: Pneumonia detected") |
|
else: |
|
st.success("Prediction: No pneumonia detected") |
|
|
|
|
|
if __name__ == '__main__': |
|
main() |
|
|