Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

app.py 1.6 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  1. import streamlit as st
  2. from PIL import Image, ImageOps
  3. import cv2
  4. import tensorflow as tf
  5. from keras.models import load_model
  6. import numpy as np
  7. class_names = ["Healthy", "Maize Streak Virus"]
  8. def load_best_model():
  9. return load_model('artifacts/model.h5')
  10. def import_and_predict(image_data, model):
  11. size = (224,224)
  12. image = ImageOps.fit(image_data, size)
  13. image = np.asarray(image)
  14. img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
  15. img_reshape = img[np.newaxis,...]
  16. prediction = model.predict(img_reshape)
  17. return prediction
  18. st.markdown("## Maize Streak Disease Classification", unsafe_allow_html=True)
  19. with st.spinner('Model is being loaded..'):
  20. best_model = load_best_model()
  21. st.write("""
  22. Despite the fact that the agricultural sector is a national economic development priority in sub-Saharan Africa, crop pests and diseases have been the challenge affecting major food security crops like maize.
  23. Maize Streak Disease which is caused by the Maize Streak Virus is regarded as the third most serious disease affecting maize in sub-Saharan Africa.
  24. """)
  25. file = st.file_uploader("Please upload the image file", type=["jpg", "png"])
  26. if file is None:
  27. st.text("File has not been uploaded yet.")
  28. else:
  29. image = Image.open(file)
  30. st.image(image, use_column_width=True)
  31. predictions = import_and_predict(image, best_model)
  32. score = tf.nn.softmax(predictions[0])
  33. st.write(score)
  34. result_text = "This image most likely belongs to the <b>{}</b> class.".format(class_names[np.argmax(score)])
  35. st.markdown(result_text, unsafe_allow_html=True)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...