elsoori commited on
Commit
aca3e20
1 Parent(s): 405de0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -5,6 +5,7 @@ import numpy as np
5
  import pandas as pd
6
  import requests
7
  from io import BytesIO
 
8
 
9
  # Initialize Streamlit app
10
  st.title("Blood Cell Detection with YOLOv8")
@@ -18,6 +19,9 @@ model.overrides['iou'] = 0.45 # NMS IoU threshold
18
  model.overrides['agnostic_nms'] = False # NMS class-agnostic
19
  model.overrides['max_det'] = 1000 # Maximum number of detections per image
20
 
 
 
 
21
  # File uploader for image input
22
  uploaded_file = st.file_uploader("Upload an image for detection", type=["jpg", "png"])
23
 
@@ -39,7 +43,9 @@ if uploaded_file:
39
 
40
  # Count the number of each cell type
41
  cell_counts = {"RBC": 0, "WBC": 0, "Platelets": 0}
42
-
 
 
43
  # Display details of detected boxes
44
  st.write("Detection Results:")
45
  for box in results[0].boxes:
@@ -48,6 +54,7 @@ if uploaded_file:
48
  cell_counts["RBC"] += 1
49
  elif class_index == 2: # WBC
50
  cell_counts["WBC"] += 1
 
51
  elif class_index == 0: # Platelets
52
  cell_counts["Platelets"] += 1
53
 
@@ -59,6 +66,13 @@ if uploaded_file:
59
  # Display the counts of each cell type
60
  st.write("Cell Type Counts:")
61
  st.write(pd.DataFrame.from_dict(cell_counts, orient='index', columns=['Count']))
62
-
 
 
 
 
 
 
 
63
  else:
64
  st.write("Upload an image to start detection.")
 
5
  import pandas as pd
6
  import requests
7
  from io import BytesIO
8
+ from fastai.vision.all import load_learner
9
 
10
  # Initialize Streamlit app
11
  st.title("Blood Cell Detection with YOLOv8")
 
19
  model.overrides['agnostic_nms'] = False # NMS class-agnostic
20
  model.overrides['max_det'] = 1000 # Maximum number of detections per image
21
 
22
+ # Load the FastAI model for WBC identification
23
+ fastai_model = load_learner('model1.pkl')
24
+
25
  # File uploader for image input
26
  uploaded_file = st.file_uploader("Upload an image for detection", type=["jpg", "png"])
27
 
 
43
 
44
  # Count the number of each cell type
45
  cell_counts = {"RBC": 0, "WBC": 0, "Platelets": 0}
46
+
47
+ # Count cells and check for WBC
48
+ has_wbc = False
49
  # Display details of detected boxes
50
  st.write("Detection Results:")
51
  for box in results[0].boxes:
 
54
  cell_counts["RBC"] += 1
55
  elif class_index == 2: # WBC
56
  cell_counts["WBC"] += 1
57
+ has_wbc = True # WBC detected
58
  elif class_index == 0: # Platelets
59
  cell_counts["Platelets"] += 1
60
 
 
66
  # Display the counts of each cell type
67
  st.write("Cell Type Counts:")
68
  st.write(pd.DataFrame.from_dict(cell_counts, orient='index', columns=['Count']))
69
+ # If a WBC is detected, run the second model
70
+ if has_wbc:
71
+ # Perform inference with the FastAI model
72
+ pred, idx, probs = fastai_model.predict(image)
73
+ st.write("White Blood Cell Classification:")
74
+ categories = ('EOSINOPHIL', 'LYMPHOCYTE', 'MONOCYTE', 'NEUTROPHIL')
75
+ results_dict = dict(zip(categories, map(float, probs)))
76
+ st.write(results_dict)
77
  else:
78
  st.write("Upload an image to start detection.")