shamimjony1000 commited on
Commit
6e1cd5d
1 Parent(s): 7ec3389

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -4
app.py CHANGED
@@ -3,7 +3,6 @@ import streamlit as st
3
  from tensorflow.keras.preprocessing import image
4
  from tensorflow.keras.models import load_model
5
  from tensorflow.keras.applications.resnet50 import preprocess_input
6
- import matplotlib.pyplot as plt
7
 
8
  # Load the trained model
9
  model_path = 'my_cnn.h5' # or '/content/my_model.keras'
@@ -30,15 +29,35 @@ def classify_image(img):
30
  # Streamlit application
31
  def main():
32
  st.title("Mosquito Species Classification")
33
- st.write("Upload a mosquito image to classify its species.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  # File uploader for image input
36
- uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
37
 
38
  if uploaded_file is not None:
39
  # Load the image for display
40
  img = image.load_img(uploaded_file, target_size=(224, 224))
41
- st.image(img, caption='Uploaded Image', use_column_width=True)
42
 
43
  # Classify the image
44
  result, probabilities = classify_image(img)
 
3
  from tensorflow.keras.preprocessing import image
4
  from tensorflow.keras.models import load_model
5
  from tensorflow.keras.applications.resnet50 import preprocess_input
 
6
 
7
  # Load the trained model
8
  model_path = 'my_cnn.h5' # or '/content/my_model.keras'
 
29
  # Streamlit application
30
  def main():
31
  st.title("Mosquito Species Classification")
32
+ st.write("Upload a mosquito image or select an example image to classify its species.")
33
+
34
+ # Example images
35
+ example_images = {
36
+ "Aedes Aegypti": "Aedes_aegypti_1_0_832.jpg",
37
+ "Anopheles Stephensi": "Anopheles_stephensi_1_0_364.jpg",
38
+ "Culex Quinquefasciatus": "Culex_quinquefasciatus_1_0_1307.jpg",
39
+ }
40
+
41
+ # Select an example image
42
+ selected_example = st.selectbox("Or select an example image:", list(example_images.keys()))
43
+
44
+ if selected_example:
45
+ img_path = example_images[selected_example]
46
+ img = image.load_img(img_path, target_size=(224, 224))
47
+ st.image(img, caption=f'Selected Example Image: {selected_example}', width=224)
48
+
49
+ # Classify the example image
50
+ result, probabilities = classify_image(img)
51
+ st.write(f'Predicted mosquito species: **{result}**')
52
+ st.write(f'Prediction probabilities: {probabilities}')
53
 
54
  # File uploader for image input
55
+ uploaded_file = st.file_uploader("Or upload your own image...", type=["jpg", "jpeg", "png"])
56
 
57
  if uploaded_file is not None:
58
  # Load the image for display
59
  img = image.load_img(uploaded_file, target_size=(224, 224))
60
+ st.image(img, caption='Uploaded Image', width=224)
61
 
62
  # Classify the image
63
  result, probabilities = classify_image(img)