Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from fastai.vision.all import load_learner | |
| from fastai import * | |
| import torch | |
| import os | |
| from PIL import Image | |
| import pandas as pd | |
| model_path = 'multi_target_resnet34.pkl' | |
| helper_csv = 'info.csv' | |
| df = pd.read_csv(helper_csv) | |
| model = load_learner(model_path) | |
| def result(path): | |
| pred,_,probability = model.predict(path) | |
| arr = ['Species','Scientific_Name','Name','Conservation_Status','Color','habitat','Found_In','Diet'] | |
| vals = ['','','','','','','',''] | |
| # pred = ['Acrantophis madagascariensis', 'Carnivore', 'Critically Endangered', 'Forest', 'Gray', 'Madagascar', 'Madagascar ground boa ', 'Snake'] | |
| for x in pred: | |
| val = df[df['values'] == x]['columns'].values[0] | |
| ind = arr.index(val) | |
| vals[ind] = x | |
| return f'{arr[0]}:\t{vals[0]}\n{arr[1]}:\t{vals[1]}\n{arr[2]}:\t{vals[2]}\n{arr[3]}:\t{vals[3]}\n{arr[4]}:\t{vals[4]}\n{arr[5]}:\t{vals[5]}\n{arr[6]}:\t{vals[6]}\n{arr[7]}:\t{vals[7]}\n' | |
| path = 'test images/' | |
| image_path = [] | |
| for i in os.listdir(path): | |
| image_path.append(path+i) | |
| image = gr.inputs.Image(shape =(300,300)) | |
| label = gr.outputs.Label() | |
| iface = gr.Interface(fn=result, inputs=image, outputs='text', examples = image_path) | |
| iface.launch(inline = False) | |