import streamlit as st import tensorflow as tf from PIL import Image import io import numpy as np from streamlit_option_menu import option_menu import base64 #add botanical names and usefulness useful = "Ornamental plant with colorful foliage and unique inflorescence" # Function to add a background image def add_bg_from_local(image_path): with open(image_path, "rb") as image_file: encoded_string = base64.b64encode(image_file.read()) st.markdown( f""" """, unsafe_allow_html=True ) # Add background image add_bg_from_local('flower_bg.jpg') 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.convert("RGB") # Convert image to RGB mode 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 # Define a dictionary mapping each flower's common name to its botanical name def predict(model, labels, img): french_names = { "pink primrose": "Primevère rose", "hard-leaved pocket orchid": "Orchidée à feuilles dures", "canterbury bells": "Clochettes de Canterbury", "sweet pea": "Pois de senteur", "english marigold": "Souci officinal", "tiger lily": "Lis tigré", "moon orchid": "Orchidée de lune", "bird of paradise": "Oiseau de paradis", "monkshood": "Aconit", "globe thistle": "Chardon boule", "snapdragon": "Muflier", "colt's foot": "Tussilage", "king protea": "Protéa roi", "spear thistle": "Chardon lancéolé", "yellow iris": "Iris jaune", "globe-flower": "Trolle", "purple coneflower": "Échinacée pourpre", "peruvian lily": "Lys des Incas", "balloon flower": "Platycodon", "giant white arum lily": "Arum géant blanc", "fire lily": "Lis de feu", "pincushion flower": "Scabieuse", "fritillary": "Fritillaire", "red ginger": "Gingembre rouge", "grape hyacinth": "Muscari", "corn poppy": "Coquelicot", "prince of wales feathers": "Amarante queue-de-renard", "stemless gentian": "Gentiane acaule", "artichoke": "Artichaut", "sweet william": "Œillet de poète", "carnation": "Œillet", "garden phlox": "Phlox de jardin", "love in the mist": "Nigelle de Damas", "mexican aster": "Cosmos", "alpine sea holly": "Chardon bleu des Alpes", "ruby-lipped cattleya": "Cattleya à lèvres rubis", "cape flower": "Fleur du Cap", "great masterwort": "Grande astrance", "siam tulip": "Tulipe de Siam", "lenten rose": "Rose de carême", "barbeton daisy": "Gerbera", "daffodil": "Jonquille", "sword lily": "Glaïeul", "poinsettia": "Poinsettia", "bolero deep blue": "Lisianthus bleu profond", "wallflower": "Giroflée", "marigold": "Tagète", "buttercup": "Renoncule", "oxeye daisy": "Marguerite", "common dandelion": "Pissenlit", "petunia": "Pétunia", "wild pansy": "Pensée sauvage", "primula": "Primevère", "sunflower": "Tournesol", "pelargonium": "Pélargonium", "bishop of llandaff": "Dahlia Bishop of Llandaff", "gaura": "Gaura", "geranium": "Géranium", "orange dahlia": "Dahlia orange", "pink-yellow dahlia": "Dahlia rose-jaune", "cautleya spicata": "Cautleya spicata", "japanese anemone": "Anémone du Japon", "black-eyed susan": "Rudbeckie", "silverbush": "Convolvulus argenté", "californian poppy": "Pavot de Californie", "osteospermum": "Ostéospermum", "spring crocus": "Crocus de printemps", "bearded iris": "Iris barbu", "windflower": "Anémone sylvie", "tree poppy": "Pavot en arbre", "gazania": "Gazanie", "azalea": "Azalée", "water lily": "Nénuphar", "rose": "Rose", "thorn apple": "Datura", "morning glory": "Liseron", "passion flower": "Passiflore", "lotus": "Lotus", "toad lily": "Tricyrtis", "anthurium": "Anthurium", "frangipani": "Frangipanier", "clematis": "Clématite", "hibiscus": "Hibiscus", "columbine": "Ancolie", "desert-rose": "Rose du désert", "tree mallow": "Lavatère", "magnolia": "Magnolia", "cyclamen": "Cyclamen", "watercress": "Cresson", "canna lily": "Canna", "hippeastrum": "Hippeastrum", "bee balm": "Monarde", "ball moss": "Tillandsia", "foxglove": "Digitale", "bougainvillea": "Bougainvillée", "camellia": "Camélia", "mallow": "Mauve", "mexican petunia": "Pétunia mexicain", "bromelia": "Bromélia", "blanket flower": "Gaillarde", "trumpet creeper": "Bignone", "blackberry lily": "Belamcanda chinensis" } botanical_names = { "pink primrose": "Primula polyantha", "hard-leaved pocket orchid": "Calypso bulbosa", "canterbury bells": "Campanula medium", "sweet pea": "Lathyrus odoratus", "english marigold": "Calendula officinalis", "tiger lily": "Lilium lancifolium", "moon orchid": "Phalaenopsis amabilis", "bird of paradise": "Strelitzia reginae", "monkshood": "Aconitum napellus", "globe thistle": "Echinops ritro", "snapdragon": "Antirrhinum majus", "colt's foot": "Tussilago farfara", "king protea": "Protea cynaroides", "spear thistle": "Cirsium vulgare", "yellow iris": "Iris pseudacorus", "globe-flower": "Trollius europaeus", "purple coneflower": "Echinacea purpurea", "peruvian lily": "Alstroemeria aurea", "balloon flower": "Platycodon grandiflorus", "giant white arum lily": "Zantedeschia aethiopica", "fire lily": "Lilium bulbiferum", "pincushion flower": "Scabiosa atropurpurea", "fritillary": "Fritillaria imperialis", "red ginger": "Alpinia purpurata", "grape hyacinth": "Muscari", "corn poppy": "Papaver rhoeas", "prince of wales feathers": "Amaranthus caudatus", "stemless gentian": "Gentiana acaulis", "artichoke": "Cynara cardunculus", "sweet william": "Dianthus barbatus", "carnation": "Dianthus caryophyllus", "garden phlox": "Phlox paniculata", "love in the mist": "Nigella damascena", "mexican aster": "Cosmos bipinnatus", "alpine sea holly": "Eryngium alpinum", "ruby-lipped cattleya": "Cattleya labiata", "cape flower": "Mesembryanthemum crystallinum", "great masterwort": "Astrantia major", "siam tulip": "Curcuma alismatifolia", "lenten rose": "Helleborus orientalis", "barbeton daisy": "Gerbera jamesonii", "daffodil": "Narcissus", "sword lily": "Gladiolus", "poinsettia": "Euphorbia pulcherrima", "bolero deep blue": "Eustoma grandiflorum", "wallflower": "Erysimum", "marigold": "Tagetes", "buttercup": "Ranunculus", "oxeye daisy": "Leucanthemum vulgare", "common dandelion": "Taraxacum officinale", "petunia": "Petunia", "wild pansy": "Viola tricolor", "primula": "Primula", "sunflower": "Helianthus", "pelargonium": "Pelargonium", "bishop of llandaff": "Dahlia", "gaura": "Gaura", "geranium": "Geranium", "orange dahlia": "Dahlia", "pink-yellow dahlia": "Dahlia", "cautleya spicata": "Cautleya spicata", "japanese anemone": "Anemone hupehensis", "black-eyed susan": "Rudbeckia hirta", "silverbush": "Convolvulus cneorum", "californian poppy": "Eschscholzia californica", "osteospermum": "Osteospermum", "spring crocus": "Crocus vernus", "bearded iris": "Iris germanica", "windflower": "Anemone nemorosa", "tree poppy": "Dendromecon rigida", "gazania": "Gazania", "azalea": "Rhododendron", "water lily": "Nymphaea", "rose": "Rosa", "thorn apple": "Datura", "morning glory": "Ipomoea", "passion flower": "Passiflora", "lotus": "Nelumbo nucifera", "toad lily": "Tricyrtis hirta", "anthurium": "Anthurium", "frangipani": "Plumeria", "clematis": "Clematis", "hibiscus": "Hibiscus", "columbine": "Aquilegia", "desert-rose": "Adenium obesum", "tree mallow": "Malva arborea", "magnolia": "Magnolia", "cyclamen": "Cyclamen", "watercress": "Nasturtium officinale", "canna lily": "Canna", "hippeastrum": "Hippeastrum", "bee balm": "Monarda", "ball moss": "Tillandsia recurvata", "foxglove": "Digitalis purpurea", "bougainvillea": "Bougainvillea", "camellia": "Camellia", "mallow": "Malva", "mexican petunia": "Ruellia brittoniana", "bromelia": "Bromelia", "blanket flower": "Gaillardia", "trumpet creeper": "Campsis radicans", "blackberry lily": "Belamcanda chinensis", # Add the botanical names for the rest of the flowers # You can use online resources to find the botanical names for each flower } # Define a dictionary mapping each flower's common name to its usefulness or importance usefulness = { "pink primrose": "Used in herbal medicine for its anti-inflammatory properties", "hard-leaved pocket orchid": "Rare and endangered species, protected by conservation efforts", "canterbury bells": "Ornamental garden plant, attracts bees and butterflies", "sweet pea": "Popular ornamental plant known for its fragrance and colorful flowers", "english marigold": "Used in traditional medicine and culinary applications", "tiger lily": "Ornamental garden plant, symbolizing wealth and prosperity in some cultures", "moon orchid": "Highly valued ornamental plant, often used in floral arrangements", "bird of paradise": "Distinctive and exotic ornamental plant, symbolizing freedom and beauty", "monkshood": "Highly toxic plant used in traditional medicine with extreme caution", "globe thistle": "Ornamental garden plant, attracts pollinators such as bees and butterflies", "snapdragon": "Popular garden plant with colorful flowers, often used in floral arrangements", "colt's foot": "Used in traditional medicine for its expectorant properties", "king protea": "National flower of South Africa, symbolizing diversity and courage", "spear thistle": "Prickly plant with ornamental value and historical significance", "yellow iris": "Ornamental water plant, attracts pollinators such as bees and butterflies", "globe-flower": "Ornamental garden plant, symbolizing happiness and good fortune", "purple coneflower": "Medicinal plant used to boost the immune system and treat colds", "peruvian lily": "Ornamental garden plant with colorful flowers, often used in floral arrangements", "balloon flower": "Ornamental garden plant, symbolizing unchanging love and devotion", "giant white arum lily": "Ornamental garden plant, often used in bridal bouquets", "fire lily": "Ornamental garden plant, symbolizing passion and desire", "pincushion flower": "Ornamental garden plant, attracts pollinators such as bees and butterflies", "fritillary": "Ornamental garden plant, known for its unique bell-shaped flowers", "red ginger": "Ornamental garden plant, prized for its vibrant red inflorescence", "grape hyacinth": "Ornamental garden plant, symbolizing rebirth and renewal", "corn poppy": "Symbolic flower of remembrance, often found in fields and meadows", "prince of wales feathers": "Ornamental garden plant, known for its striking red inflorescence", "stemless gentian": "Medicinal plant used to treat digestive disorders", "artichoke": "Edible plant cultivated for its edible flower buds", "sweet william": "Ornamental garden plant with fragrant flowers, symbolizing gallantry", "carnation": "Popular cut flower with various symbolic meanings, often used in bouquets", "garden phlox": "Ornamental garden plant, attracts pollinators such as bees and butterflies", "love in the mist": "Ornamental garden plant with delicate flowers, symbolizing affection", "mexican aster": "Ornamental garden plant with colorful flowers, attracts pollinators", "alpine sea holly": "Ornamental garden plant, known for its distinctive blue flowers", "ruby-lipped cattleya": "Highly prized orchid species, often used in corsages", "cape flower": "Ornamental garden plant, symbolizing resilience and endurance", "great masterwort": "Medicinal plant used to treat various ailments", "siam tulip": "Ornamental garden plant, symbolizing prosperity and abundance", "lenten rose": "Ornamental garden plant, prized for its early blooming flowers", "barbeton daisy": "Ornamental garden plant with colorful flowers, attracts pollinators", "daffodil": "Symbolic flower of renewal and hope, often associated with spring", "sword lily": "Ornamental garden plant with striking sword-shaped leaves", "poinsettia": "Popular ornamental plant, often used as a decorative plant during the holidays", "bolero deep blue": "Ornamental garden plant with deep blue flowers, symbolizing tranquility", "wallflower": "Ornamental garden plant, known for its fragrant flowers", "marigold": "Used in traditional medicine and culinary applications, often planted to repel pests", "buttercup": "Ornamental garden plant with bright yellow flowers", "oxeye daisy": "Ornamental garden plant with daisy-like flowers, symbolizing innocence", "common dandelion": "Edible plant with various medicinal properties", "petunia": "Popular garden plant with colorful flowers, symbolizing playfulness", "wild pansy": "Medicinal plant used to treat respiratory ailments", "primula": "Ornamental garden plant, known for its early spring blooms", "sunflower": "Symbolic flower of happiness and vitality, cultivated for its edible seeds", "pelargonium": "Ornamental garden plant, known for its fragrant leaves and flowers", "bishop of llandaff": "Ornamental garden plant with deep red flowers", "gaura": "Ornamental garden plant with delicate flowers, attracts pollinators", "geranium": "Popular garden plant with colorful flowers and fragrant leaves", "orange dahlia": "Ornamental garden plant with vibrant orange flowers", "pink-yellow dahlia": "Ornamental garden plant with pink and yellow bicolor flowers", "cautleya spicata": "Ornamental garden plant, known for its showy flowers", "japanese anemone": "Ornamental garden plant with delicate flowers, symbolizing protection", "black-eyed susan": "Ornamental garden plant with yellow flowers and dark centers", "silverbush": "Ornamental garden plant with silvery foliage", "californian poppy": "Ornamental garden plant with bright orange flowers", "osteospermum": "Ornamental garden plant with colorful daisy-like flowers", "spring crocus": "Ornamental garden plant with early spring blooms", "bearded iris": "Ornamental garden plant with showy flowers, often used in landscaping", "windflower": "Ornamental garden plant with delicate flowers, symbolizing anticipation", "tree poppy": "Ornamental garden plant with bright yellow flowers", "gazania": "Ornamental garden plant with colorful flowers, drought tolerant", "azalea": "Ornamental garden plant with vibrant flowers, symbolizing passion", "water lily": "Ornamental water plant, symbolizing purity and enlightenment", "rose": "Symbolic flower of love and romance, cultivated for its beauty and fragrance", "thorn apple": "Historically used in herbal medicine, highly toxic if ingested", "morning glory": "Ornamental garden plant with colorful flowers, symbolizing affection", "passion flower": "Symbolic flower of Christ's passion, often used in religious art", "lotus": "Symbolic flower of purity and enlightenment in various cultures", "toad lily": "Ornamental garden plant with unique spotted flowers", "anthurium": "Ornamental plant with distinctive heart-shaped flowers, symbolizing hospitality and abundance", "frangipani": "Ornamental garden plant with fragrant flowers, often used in tropical landscaping", "clematis": "Ornamental garden plant with colorful flowers, symbolizing mental beauty", "hibiscus": "Edible plant with medicinal properties, popular ornamental garden plant", "columbine": "Ornamental garden plant with unique spurred flowers, symbolizing love and fidelity", "desert-rose": "Ornamental garden plant with succulent foliage and colorful flowers", "tree mallow": "Ornamental garden plant with large colorful flowers", "magnolia": "Ornamental garden plant with large fragrant flowers, symbolizing nobility and perseverance", "cyclamen": "Ornamental garden plant with unique twisted flowers, symbolizing resignation and farewell", "watercress": "Edible aquatic plant, rich in vitamins and minerals", "canna lily": "Ornamental garden plant with colorful flowers and edible rhizomes", "hippeastrum": "Ornamental garden plant with large showy flowers, symbolizing pride and beauty", "bee balm": "Medicinal plant with aromatic leaves and flowers, attracts pollinators", "ball moss": "Epiphytic plant that grows on trees, contributes to ecosystem biodiversity", "foxglove": "Medicinal plant used to treat heart conditions, highly toxic if ingested", "bougainvillea": "Ornamental vine with vibrant flowers, drought tolerant", "camellia": "Ornamental garden plant with evergreen leaves and showy flowers", "mallow": "Edible and medicinal plant with soothing properties", "mexican petunia": "Ornamental garden plant with colorful flowers, attracts butterflies", "bromelia": "Ornamental plant with colorful foliage and unique inflorescence", "blanket flower": "Ornamental garden plant with daisy-like flowers, drought tolerant", "trumpet creeper": "Ornamental vine with trumpet-shaped flowers, attracts hummingbirds", "blackberry lily": "Ornamental garden plant with iris-like flowers and blackberry-like fruits" # Add the usefulness or importance for the rest of the flowers } 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) get_flower = flower # Debug: Print the predicted flower name #print(f"Predicted Flower: {flower}") #print(f"Predicted Flower: {get_flower}") print(botanical_names[get_flower]) botanical_name = botanical_names.get(get_flower, "Unknown") flower_usefulness = usefulness.get(get_flower, "Unknown") french_name = french_names.get(get_flower, "Unknown") # Debug: Print the botanical name and usefulness print(f"Botanical Name: {botanical_name}") print(f"Usefulness: {flower_usefulness}") return flower, closeness, botanical_name, flower_usefulness, french_name def main(): with st.sidebar: selected = option_menu( menu_title="Main Menu", options=["Home", "About", "Local Classifier", "Extensive Classifier", "Project Details"], icons=["house", "info-circle", "camera", "search", "clipboard-list"], menu_icon="cast", default_index=0, ) if selected == "Home": st.markdown("""

Home

Click the link below to visit the main application page:

Go to Main Application """, unsafe_allow_html=True) elif selected == "About": st.markdown('

About

') st.markdown("""

NAME:
TOLULOPE

CLASS:
HND2

LEVEL:
400L

SCHOOL:
FEDERAL COLLEGE OF ANIMAL HEALTH AND PRODUCTION TECHNOLOGY.

SUPERVISOR:

""", unsafe_allow_html=True) elif selected == "Extensive Classifier": st.markdown('

Extensive Classifier

', unsafe_allow_html=True) st.markdown('

This is a demo of an image classification model trained on the Oxford Flower Dataset.

', unsafe_allow_html=True) st.markdown('

To test the model, upload an image of a flower and click the Run on image button.

', unsafe_allow_html=True) 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 extensive results..._**') flower, closeness, botanical_name, flower_usefulness, french_name = predict(model, labels, image) st.markdown(f'
Flower Type: {flower}
', unsafe_allow_html=True) st.markdown(f'
Closeness: {closeness}%
', unsafe_allow_html=True) st.markdown(f'
Botanical Name: {botanical_name}
', unsafe_allow_html=True) st.markdown(f'
Usefulness/Description: {flower_usefulness}
', unsafe_allow_html=True) st.markdown(f'
French Name: {french_name}
', unsafe_allow_html=True) elif selected == "Local Classifier": st.markdown('

Local Classifier

', unsafe_allow_html=True) st.markdown('

This section contains a local classifier details and options.

', unsafe_allow_html=True) # Add your extensive classifier code here 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 local results..._**') flower, closeness, botanical_name, flower_usefulness, french_name = predict(model, labels, image) st.markdown(f'
Flower Type: {flower}
', unsafe_allow_html=True) st.markdown(f'
Closeness: {closeness}%
', unsafe_allow_html=True) st.markdown(f'
French Name: {french_name}
', unsafe_allow_html=True) elif selected == "Project Details": st.markdown('

Project Details

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

This project is about classifying flowers using deep learning. The Oxford Flower Dataset, consisting of 102 flower categories, is used for training the model. 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.

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