Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import PIL.Image as Image
|
| 3 |
import numpy as np
|
| 4 |
import pandas as pd
|
| 5 |
import requests
|
| 6 |
from io import BytesIO
|
| 7 |
-
from fastai.vision.all import load_learner
|
| 8 |
|
| 9 |
# Initialize Streamlit app
|
| 10 |
st.title("White Blood Cell Classifier")
|
| 11 |
|
| 12 |
# Load the FastAI model for WBC identification
|
| 13 |
-
fastai_model = load_learner('model1.pkl')
|
| 14 |
|
| 15 |
# File uploader for image input
|
| 16 |
uploaded_file = st.file_uploader("Upload an image for classification", type=["jpg", "png"])
|
|
@@ -19,17 +20,35 @@ if uploaded_file:
|
|
| 19 |
# Open the uploaded image
|
| 20 |
image = Image.open(uploaded_file)
|
| 21 |
|
| 22 |
-
# Display the uploaded image
|
| 23 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 24 |
|
| 25 |
# Perform inference with the FastAI model
|
| 26 |
pred, idx, probs = fastai_model.predict(image)
|
| 27 |
-
|
| 28 |
-
# Display
|
| 29 |
-
st.
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
else:
|
| 35 |
-
st.
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
import streamlit as st
|
| 3 |
import PIL.Image as Image
|
| 4 |
import numpy as np
|
| 5 |
import pandas as pd
|
| 6 |
import requests
|
| 7 |
from io import BytesIO
|
| 8 |
+
from fastai.vision.all import load_learner # Corrected import
|
| 9 |
|
| 10 |
# Initialize Streamlit app
|
| 11 |
st.title("White Blood Cell Classifier")
|
| 12 |
|
| 13 |
# Load the FastAI model for WBC identification
|
| 14 |
+
fastai_model = load_learner('model1.pkl')
|
| 15 |
|
| 16 |
# File uploader for image input
|
| 17 |
uploaded_file = st.file_uploader("Upload an image for classification", type=["jpg", "png"])
|
|
|
|
| 20 |
# Open the uploaded image
|
| 21 |
image = Image.open(uploaded_file)
|
| 22 |
|
| 23 |
+
# Display the uploaded image with a caption
|
| 24 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 25 |
|
| 26 |
# Perform inference with the FastAI model
|
| 27 |
pred, idx, probs = fastai_model.predict(image)
|
| 28 |
+
|
| 29 |
+
# Display a title for the results section
|
| 30 |
+
st.subheader("White Blood Cell Classification Results")
|
| 31 |
+
|
| 32 |
+
# Define categories for classification
|
| 33 |
+
categories = ('EOSINOPHIL', 'LYMPHOCYTE', 'MONOCYTE', 'NEUTROPHIL')
|
| 34 |
+
|
| 35 |
+
# Create a DataFrame with classification probabilities
|
| 36 |
+
results_df = pd.DataFrame(
|
| 37 |
+
{'Cell Type': categories, 'Probability': probs.tolist()}
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
# Display the probabilities as a bar chart
|
| 41 |
+
st.bar_chart(results_df.set_index('Cell Type'))
|
| 42 |
+
|
| 43 |
+
# Highlight the most likely class
|
| 44 |
+
most_likely_class = categories[idx]
|
| 45 |
+
st.success(f"Predicted Class: {most_likely_class}")
|
| 46 |
+
|
| 47 |
+
# Additional information about the probabilities
|
| 48 |
+
st.write("Detailed Classification Results:")
|
| 49 |
+
st.table(results_df)
|
| 50 |
|
| 51 |
else:
|
| 52 |
+
st.warning("Upload an image to start classification.")
|
| 53 |
+
|
| 54 |
+
|