File size: 2,083 Bytes
a12a4a3
 
 
 
 
1b1d034
0130086
1b1d034
 
 
 
0130086
 
 
 
 
 
 
 
1b1d034
3f37e7e
1b1d034
b8fcc9f
5892748
3f37e7e
5892748
 
968d374
 
5892748
 
4784d5e
3f37e7e
5892748
 
3f37e7e
5892748
 
3f37e7e
5892748
 
3f37e7e
5892748
 
 
 
62b8c0c
5892748
 
3f37e7e
5892748
 
 
3f37e7e
62b8c0c
 
 
 
5892748
 
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
58
59
60
61
import streamlit as st
import PIL.Image as Image
import numpy as np
import pandas as pd
import requests
from io import BytesIO
from fastai.vision.all import load_learner  

# Initialize Streamlit app
st.title("White Blood Cell Classifier")

# Add a description or subtitle
st.markdown("""
This app allows you to classify white blood cells from an uploaded image. 
You can upload an image of a blood sample, and the app will predict the type of white blood cell present. 
Choose from various cell types like eosinophil, lymphocyte, monocyte, and neutrophil.
Note: To get the best results, please make sure there is only one WBC in the image. This model has not been trained on basophils.
""")

# Load the FastAI model for WBC identification
fastai_model = load_learner('model1.pkl')

# File uploader for image input
uploaded_file = st.file_uploader("Upload an image for classification", type=["jpg", "png"])

if uploaded_file:
    # Open the uploaded image
    image = Image.open(uploaded_file).convert('RGB')

    
    # Display the uploaded image with a caption
    st.image(image, caption="Reduced Size Image", use_column_width=False, width=150)  # 150 pixels wide

    # Perform inference with the FastAI model
    pred, idx, probs = fastai_model.predict(image)

    # Display a title for the results section
    st.subheader("White Blood Cell Classification Results")

    # Define categories for classification
    categories = ('EOSINOPHIL', 'LYMPHOCYTE', 'MONOCYTE', 'NEUTROPHIL')

    # Create a DataFrame with classification probabilities
    results_df = pd.DataFrame(
        {'Cell Type': categories, 'Probability': probs.tolist()}
    )
     # Highlight the most likely class
    most_likely_class = categories[idx]
    st.success(f"Predicted Class: {most_likely_class}")

    # Additional information about the probabilities
    st.write("Detailed Classification Results:")
    st.table(results_df)

    # Display the probabilities as a bar chart
    st.bar_chart(results_df.set_index('Cell Type'))

   
else:
    st.warning("Upload an image to start classification.")