-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
31 lines (24 loc) · 1.03 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
#import
import os
import keras
from keras.models import load_model
import streamlit as st
import tensorflow as tf
import numpy as np
st.header('Flower Classification CNN Model')
flower_names = ['daisy', 'dandelion', 'rose', 'sunflower', 'tulip']
model = load_model('Flower_Recog_Model.h5')
def classify_images(image_path):
input_image = tf.keras.utils.load_img(image_path, target_size = (180, 180))
input_image_array = tf.keras.utils.img_to_array(input_image)
input_image_exp_dim = tf.expand_dims(input_image_array, 0)
predictions = model.predict(input_image_exp_dim)
result = tf.nn.softmax(predictions[0])
outcome = 'The Image belongs to ' + flower_names[np.argmax(result)] + ' with a score of ' + str(np.max(result)*100)
return outcome
uploaded_file = st.file_uploader('Upload an Image')
if uploaded_file is not None:
with open(os.path.join('upload', uploaded_file.name), 'wb') as f:
f.write(uploaded_file.getbuffer())
st.image(uploaded_file, width = 200)
st.markdown(classify_images(uploaded_file))