Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import os | |
| import numpy as np | |
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| from tensorflow.keras.applications import ResNet50V2 | |
| from tensorflow.keras.models import Sequential, load_model | |
| from tensorflow.keras.layers import Dense | |
| from tensorflow.keras.utils import to_categorical | |
| from tensorflow.keras.applications.resnet_v2 import preprocess_input | |
| from tensorflow.keras.preprocessing.image import load_img, img_to_array | |
| image_folders = ['King_Crab', 'Wind_Lion_God', 'pavo_cristatus', 'otter', 'Upupa_epops'] | |
| labels = ["ι±", "ιιι’¨η ηΊ", "ιιθει", "ζδΊζ°΄ηΊ", "ιιζ΄ει³₯"] | |
| base_dir = './' | |
| thedir = base_dir + image_folders[0] | |
| os.listdir(thedir) | |
| data = [] | |
| target = [] | |
| for i in range(5): | |
| thedir = base_dir + image_folders[i] | |
| image_fnames = os.listdir(thedir) | |
| for theimage in image_fnames: | |
| if theimage == ".git" or theimage == ".ipynb_checkpoints": | |
| continue | |
| img_path = thedir + '/' + theimage | |
| img = load_img(img_path , target_size = (256,256)) | |
| x = img_to_array(img) | |
| data.append(x) | |
| target.append(i) | |
| model = load_model('my_cnn_model.pb') # Loading the Tensorflow Saved Model (PB) | |
| print(model.summary()) | |
| def classify_image(inp): | |
| inp = inp.reshape((-1, 256, 256, 3)) | |
| inp = preprocess_input(inp) | |
| prediction = model.predict(inp).flatten() | |
| return {labels[i]: float(prediction[i]) for i in range(5)} | |
| image = gr.Image(shape=(256, 256), label="ιιθειγζδΊζ°΄ηΊγζ΄ει³₯η §η") | |
| label = gr.Label(num_top_classes=5, label="AIθΎ¨θη΅ζ") | |
| some_text="ζθ½θΎ¨θιιθειγζδΊζ°΄ηΊγζ΄ει³₯γζΎεΌ΅ιιθειγζδΊζ°΄ηΊγζ΄ει³₯η §ηδΎθζε§!" | |
| sample_images = [] | |
| for i in range(5): | |
| thedir = base_dir + image_folders[i] | |
| for file in os.listdir(thedir): | |
| if file == ".git" or file == ".ipynb_checkpoints": | |
| continue | |
| sample_images.append(image_folders[i] + '/' + file) | |
| gr.Interface(fn=classify_image, | |
| inputs=image, | |
| outputs=label, | |
| title="AI ιιθειγζδΊζ°΄ηΊγζ΄ει³₯θΎ¨θζ©", | |
| description=some_text, | |
| examples=sample_images, live=True).launch(share=True) | |
| # def greet(name): | |
| # model = load_model('my_cnn_model.h5') # Loading the Tensorflow Saved Model (PB) | |
| # return "Hello " + name + "!!" + model.summary() | |
| # iface = gr.Interface(fn=greet, inputs="text", outputs="text") | |
| # .launch(share=True) | |
| # iface.launch() | |