Spaces:
Runtime error
Runtime error
| from PIL import Image | |
| from tensorflow.keras.preprocessing import image | |
| import gradio as gr | |
| import numpy as np | |
| from tensorflow.keras import models | |
| model = models.load_model("ButterFlyModel2.h5") | |
| label_list = [ | |
| 'SOUTHERN DOGFACE', 'ADONIS', 'BROWN SIPROETA', 'MONARCH', | |
| 'GREEN CELLED CATTLEHEART', 'CAIRNS BIRDWING', 'EASTERN DAPPLE WHITE', | |
| 'RED POSTMAN', 'MANGROVE SKIPPER', 'BLACK HAIRSTREAK', 'CABBAGE WHITE', | |
| 'RED ADMIRAL', 'PAINTED LADY', 'PAPER KITE', 'SOOTYWING', 'PINE WHITE', | |
| 'PEACOCK', 'CHECQUERED SKIPPER', 'JULIA', 'COMMON WOOD-NYMPH', 'BLUE MORPHO', | |
| 'CLOUDED SULPHUR', 'STRAITED QUEEN', 'ORANGE OAKLEAF', 'PURPLISH COPPER', | |
| 'ATALA', 'IPHICLUS SISTER', 'DANAID EGGFLY', 'LARGE MARBLE', | |
| 'PIPEVINE SWALLOW', 'BLUE SPOTTED CROW', 'RED CRACKER', 'QUESTION MARK', | |
| 'CRIMSON PATCH', 'BANDED PEACOCK', 'SCARCE SWALLOW', 'COPPER TAIL', | |
| 'GREAT JAY', 'INDRA SWALLOW', 'VICEROY', 'MALACHITE', 'APPOLLO', | |
| 'TWO BARRED FLASHER', 'MOURNING CLOAK', 'TROPICAL LEAFWING', 'POPINJAY', | |
| 'ORANGE TIP', 'GOLD BANDED', 'BECKERS WHITE', 'RED SPOTTED PURPLE', | |
| 'MILBERTS TORTOISESHELL', 'SILVER SPOT SKIPPER', 'AMERICAN SNOOT', 'AN 88', | |
| 'ULYSES', 'COMMON BANDED AWL', 'CRECENT', 'METALMARK', 'SLEEPY ORANGE', | |
| 'PURPLE HAIRSTREAK', 'ELBOWED PIERROT', 'GREAT EGGFLY', 'ORCHARD SWALLOW', | |
| 'ZEBRA LONG WING', 'WOOD SATYR', 'MESTRA', 'EASTERN PINE ELFIN', | |
| 'EASTERN COMA', 'YELLOW SWALLOW TAIL', 'CLEOPATRA', 'GREY HAIRSTREAK', | |
| 'BANDED ORANGE HELICONIAN', 'AFRICAN GIANT SWALLOWTAIL', 'CHESTNUTQ', | |
| 'CLODIUS PARNASSIAN' | |
| ] | |
| sorted_labels = sorted(label_list) | |
| def Classifying_Butterflies(image): | |
| img = Image.fromarray(image) | |
| img_array = img.resize((150,150)) | |
| img_array = np.expand_dims(img_array, axis=0) | |
| prediction = model.predict(img_array) | |
| max_index = np.argmax(prediction) # getting the index of the max value from the result array | |
| return "It is "+sorted_labels[max_index] | |
| interface = gr.Interface( | |
| fn=Classifying_Butterflies, | |
| inputs='image', | |
| outputs='text', | |
| title='Butterfly Classifier', | |
| description='Upload an image of a butterfly and let the classifier identify it!' | |
| ) | |
| interface.launch() | |