elsoori commited on
Commit
5892748
·
verified ·
1 Parent(s): 276843e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -44
app.py CHANGED
@@ -4,8 +4,7 @@ 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, untar_data, URLs
8
- import gradio as gr
9
 
10
  # Initialize Streamlit app
11
  st.title("White Blood Cell Classifier")
@@ -13,55 +12,40 @@ st.title("White Blood Cell Classifier")
13
  # Load the FastAI model for WBC identification
14
  fastai_model = load_learner('model1.pkl')
15
 
16
- # Pre-load some example images with their corresponding labels
17
- example_images = {
18
- "Eosinophil": "eosinophil.jpg",
19
- "Lymphocyte": "lymphocyte.jpg",
20
- "Monocyte": "monocyte.jpg",
21
- "Neutrophil": "neutrophil.jpg",
22
- }
23
-
24
- # Provide a choice of example images
25
- st.sidebar.header("Example Images")
26
- example_choice = st.sidebar.selectbox(
27
- "Select an example image to classify",
28
- list(example_images.keys())
29
- )
30
-
31
- # Display the chosen example image
32
- example_url = example_images[example_choice]
33
- response = requests.get(example_url)
34
- example_image = Image.open(BytesIO(response.content))
35
- st.sidebar.image(example_image, caption=f"Example: {example_choice}", use_column_width=True)
36
-
37
  # File uploader for image input
38
- uploaded_file = st.file_uploader("Upload your own image for classification", type=["jpg", "png"])
39
 
40
- # Check if an image has been uploaded or an example has been selected
41
- image_to_classify = example_image if uploaded_file is None else Image.open(uploaded_file)
 
 
 
 
42
 
43
- # Display the image being classified
44
- st.image(image_to_classify, caption="Image for Classification", use_column_width=True)
45
 
46
- # Perform inference with the FastAI model
47
- pred, idx, probs = fastai_model.predict(image_to_classify)
48
 
49
- # Display a subheader for results
50
- st.subheader("White Blood Cell Classification Results")
51
 
52
- # Define categories for classification
53
- categories = ('EOSINOPHIL', 'LYMPHOCYTE', 'MONOCYTE', 'NEUTROPHIL')
 
 
54
 
55
- # Create a DataFrame with classification probabilities
56
- results_df = pd.DataFrame({'Cell Type': categories, 'Probability': probs.tolist()})
57
 
58
- # Display probabilities as a bar chart
59
- st.bar_chart(results_df.set_index('Cell Type'))
 
60
 
61
- # Highlight the most likely class
62
- most_likely_class = categories[idx]
63
- st.success(f"Predicted Class: {most_likely_class}")
64
 
65
- # Additional information about probabilities
66
- st.write("Detailed Classification Results:")
67
- st.table(results_df)
 
4
  import pandas as pd
5
  import requests
6
  from io import BytesIO
7
+ from fastai.vision.all import load_learner # Corrected import
 
8
 
9
  # Initialize Streamlit app
10
  st.title("White Blood Cell Classifier")
 
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"])
17
 
18
+ if uploaded_file:
19
+ # Open the uploaded image
20
+ image = Image.open(uploaded_file)
21
+
22
+ # Display the uploaded image with a caption
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 a title for the results section
29
+ st.subheader("White Blood Cell Classification Results")
30
 
31
+ # Define categories for classification
32
+ categories = ('EOSINOPHIL', 'LYMPHOCYTE', 'MONOCYTE', 'NEUTROPHIL')
33
 
34
+ # Create a DataFrame with classification probabilities
35
+ results_df = pd.DataFrame(
36
+ {'Cell Type': categories, 'Probability': probs.tolist()}
37
+ )
38
 
39
+ # Display the probabilities as a bar chart
40
+ st.bar_chart(results_df.set_index('Cell Type'))
41
 
42
+ # Highlight the most likely class
43
+ most_likely_class = categories[idx]
44
+ st.success(f"Predicted Class: {most_likely_class}")
45
 
46
+ # Additional information about the probabilities
47
+ st.write("Detailed Classification Results:")
48
+ st.table(results_df)
49
 
50
+ else:
51
+ st.warning("Upload an image to start classification.")