import gradio as gr import os pkl = "all_20211108_res34.pkl" from fastai.vision.all import * from fastai.vision.widgets import * import jaconv import pathlib plt = platform.system() if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath model_inf = load_learner(pkl) print(os.getcwd()) def kinoko_uranai(img): replace_dic = {"_ッロウッ":" (group)","ー":""} result_dic = {} pred_class, pred_idxs, outputs = model_inf.predict(img) top_5_conf, i = outputs.topk(5) itr = 0 classes = model_inf.dls.vocab result_dic = {} for x in i: kwamei = jaconv.alphabet2kata(classes[x.item()].lower()) for k,v in replace_dic.items(): kwamei = kwamei.replace(k,v) result_dic[kwamei] = str(round(top_5_conf[itr].item(),2)) itr=itr+1 return result_dic outputs = gr.outputs.Label(num_top_classes=5) iface = gr.Interface(fn=kinoko_uranai, inputs="image", outputs=outputs).launch(debug=True)