hen8001 commited on
Commit
bec9d69
1 Parent(s): dee66e1

first commit

Browse files
Files changed (2) hide show
  1. cotton_app.py +39 -0
  2. cotton_crop.h5 +3 -0
cotton_app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ model = tf.keras.models.load_model('cotton_crop.h5')
3
+ import streamlit as st
4
+ st.write("""
5
+ # Cotton crop identification
6
+ """
7
+ )
8
+ #st.write("This is a simple image classification web app to predict rock-paper-scissor hand sign")
9
+ file = st.file_uploader("Please upload an image file", type=["jpg", "png"])
10
+
11
+ import cv2
12
+ from PIL import Image, ImageOps
13
+ import numpy as np
14
+ def import_and_predict(image_data, model):
15
+
16
+ size = (300,300)
17
+ image = ImageOps.fit(image_data, size, Image.ANTIALIAS)
18
+ image = np.asarray(image)
19
+ img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
20
+ img_resize = (cv2.resize(img, dsize=(300, 300), interpolation=cv2.INTER_CUBIC))/255.
21
+
22
+ img_reshape = img_resize[np.newaxis,...]
23
+
24
+ prediction = model.predict(img_reshape)
25
+
26
+ return prediction
27
+ if file is None:
28
+ st.text("Please upload an image file")
29
+ else:
30
+ image = Image.open(file)
31
+ st.image(image, use_column_width=True)
32
+ prediction = import_and_predict(image, model)
33
+
34
+ # if np.argmax(prediction) == 0:
35
+ if prediction[0][0]==1.0:
36
+ st.write("Cotton crop")
37
+ else:
38
+ st.write("Not a cotton crop")
39
+ st.write(prediction)
cotton_crop.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:889341b135a27d285b0a5cbb2887a57650bd67b3ec0d10818f6ff227a1df861f
3
+ size 2763943432