Spaces:
Sleeping
Sleeping
Initial commit
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 *
|
8 |
+
#from fastai.vision.all import load_learner
|
9 |
+
|
10 |
+
# Initialize Streamlit app
|
11 |
+
st.title("White Blood Cell Classifier")
|
12 |
+
|
13 |
+
|
14 |
+
# Load the FastAI model for WBC identification
|
15 |
+
fastai_model = load_learner('model1.pkl')
|
16 |
+
|
17 |
+
# File uploader for image input
|
18 |
+
uploaded_file = st.file_uploader("Upload an image for detection", type=["jpg", "png"])
|
19 |
+
|
20 |
+
if uploaded_file:
|
21 |
+
# Open the uploaded image
|
22 |
+
image = Image.open(uploaded_file)
|
23 |
+
|
24 |
+
# Perform inference
|
25 |
+
results = model.predict(np.array(image))
|
26 |
+
|
27 |
+
# Display results
|
28 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
29 |
+
|
30 |
+
# Render detection results
|
31 |
+
rendered_image = render_result(model=model, image=image, result=results[0])
|
32 |
+
|
33 |
+
# Show the rendered result
|
34 |
+
st.image(rendered_image, caption="Detection Results", use_column_width=True)
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
# Display the counts of each cell type
|
39 |
+
st.write("Cell Type :")
|
40 |
+
# Perform inference with the FastAI model
|
41 |
+
pred, idx, probs = fastai_model.predict(image)
|
42 |
+
st.write("White Blood Cell Classification:")
|
43 |
+
categories = ('EOSINOPHIL', 'LYMPHOCYTE', 'MONOCYTE', 'NEUTROPHIL')
|
44 |
+
results_dict = dict(zip(categories, map(float, probs)))
|
45 |
+
st.write(results_dict)
|
46 |
+
else:
|
47 |
+
st.write("Upload an image to start detection.")
|