-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
76 lines (43 loc) · 1.61 KB
/
app.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import streamlit as st
import tensorflow as tf
import numpy as np
from PIL import Image
import request
import url
st.title("Assembly AI HACKATON")
from PIL import Image
image = Image.open('descarga.png')
st.image(image, caption='Assembly AI')
def main():
st.image(image, caption='Assembly AI')
if __name__ == '__main__':
main()
st.set_option('deprecation.showfileUploaderEncoding', False)
@st.cache(allow_output_mutation=True)
def load_model():
model = tf.keras.models.load_model('./my_model.h5')
return model
def predict_class(image, model):
image = tf.cast(image, tf.float32)
image = tf.image.resize(image, [256, 256])
image = np.expand_dims(image, axis = 0)
prediction = model.predict(image)
return prediction
model = load_model()
st.title('Leaf Classifier detection using Convulutional Neural Networks')
file = st.file_uploader("Upload an image ", type=["jpg", "png"])
if file is None:
st.text('Waiting for upload....')
else:
slot = st.empty()
slot.text('Running inference....')
test_image = Image.open(file)
st.image(test_image, caption="Input Image", width = 400)
pred = predict_class(np.asarray(test_image), model)
class_names = ['Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy']
result = class_names[np.argmax(pred)]
output = 'The model predicts that the image that that you upload is ' + result
slot.text('Done')
st.success(output)
st.info('The model is a CNN doing a classification task ', icon="ℹ️")
st.success('The model is running in a inference successfully !', icon="✅")