# All imports import streamlit as st import tensorflow as tf from PIL import Image import io import numpy as np def load_image(): uploaded_file = st.file_uploader(label='Pick an image to test') if uploaded_file is not None: image_data = uploaded_file.getvalue() st.image(image_data) img = Image.open(io.BytesIO(image_data)) img = img.resize((224,224)) return img else: return None def load_model(): model_name = 'Model/model.h5' model = tf.keras.models.load_model(model_name) return model def load_labels(): with open('Oxford-102_Flower_dataset_labels.txt', 'r') as file: data = file.read().splitlines() return data def predict(model, labels, img): img_array = tf.keras.preprocessing.image.img_to_array(img) img_array = tf.expand_dims(img_array, 0) # Create a batch prediction = model.predict(img_array) predicted_class = np.argmax(prediction[0], axis=-1) flower = labels[predicted_class] closeness = np.round(prediction[0][predicted_class] * 100, 2) return flower, closeness def main(): st.title('Flower Classification Using Deep Learning ') st.markdown('### NAME:') st.write('TOLULOPE') st.markdown('### CLASS:') st.write('HND2') st.markdown('### LEVEL:') st.write('400L') st.markdown('---') st.write("This is a demo of an image classification model trained on the Oxford Flower Dataset. The Oxford Flower Dataset, consisting of 102 flower categories. The images have large scale, pose and light variations. In addition, there are categories that have large variations within the category and several very similar categories. The dataset is visualized using isomap with shape and colour features. Link to the dataset is available @ https://www.kaggle.com/datasets/yousefmohamed20/oxford-102-flower-dataset.. . To test the model, upload an image of a flower and click the 'Run on image' button.") st.markdown('---') model = load_model() labels = load_labels() image = load_image() result = st.button('Run on image') if result and image is not None: st.markdown('**_Calculating results..._**') flower, closeness = predict(model, labels, image) st.markdown(f'

Flower Type: {flower}

', unsafe_allow_html=True) st.markdown(f'

Closeness: {closeness}%

', unsafe_allow_html=True) if __name__ == '__main__': main()