Download app.py from rishabh5752/Pneumonia_detection_using_CNN: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/spaces/rishabh5752/Pneumonia_detection_using_CNN/resolve/main/app.py
- Command line
-
hf download hf://spaces/rishabh5752/Pneumonia_detection_using_CNN/app.py
-
curl -L -o app.py https://huggingface.co/spaces/rishabh5752/Pneumonia_detection_using_CNN/resolve/main/app.py
1.39 kB
| 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() | |