File size: 1,388 Bytes
efb2d12 ad887e6 efb2d12 ad887e6 efb2d12 ad887e6 efb2d12 ad887e6 efb2d12 ad887e6 b1a6758 ad887e6 5b13053 ad887e6 5b13053 ad887e6 5b13053 ad887e6 efb2d12 ad887e6 efb2d12 | 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 | import streamlit as st
import pickle
from PIL import Image
# Load the pretrained model from the pickle file
model_filename = 'model.pkl'
with open(model_filename, 'rb') as file:
model = pickle.load(file)
# Function to make predictions
def predict_pneumonia(image):
# Preprocess the image (you may need to resize or normalize it)
# preprocess_image(image)
# Make predictions using the loaded model
prediction = model.predict(image)
return prediction
# Streamlit app
def main():
# Set app title and layout
st.title("Pneumonia Detection")
st.markdown("---")
# Add an image uploader
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:
# Display the uploaded image
image = Image.open(uploaded_file)
st.image(image, caption="Uploaded Image", use_column_width=True)
# Make prediction when the user clicks the 'Predict' button
if st.button("Predict"):
# Perform prediction
prediction = predict_pneumonia(image)
# Display the prediction
if prediction == 1:
st.error("Prediction: Pneumonia detected")
else:
st.success("Prediction: No pneumonia detected")
# Run the app
if __name__ == '__main__':
main()
|