import gradio as gr from huggingface_hub import from_pretrained_fastai from fastai.vision.all import * repo_id = "Tinsae/EthioFoodtest3" learn = from_pretrained_fastai(repo_id) labels = learn.dls.vocab EXAMPLES_PATH = Path('./examples') title = "Ethiopian Food classifier " description = """ This app is a demo of a model trained to classify images of the following Ethiopian food categories - Beyaynetu, Chechebsa, Doro wat, Firfir, Genfo, Kikil, Kitfo, Shekla tibs, Shiro wat, Tihlo and Tire_siga """ article = "Full report on this model can be found [here](https://wandb.ai/tinsae/Ethiopian-foods/reports/Ethiopian-Foods-Classification---VmlldzoyMzExNjk1?accessToken=hx3g5jwmlrn059f11zp5v2ktg62ygl23mkxy2tevliu6bmqsmpazp5jkmqzjrg71)" examples = [f'{EXAMPLES_PATH}/{f.name}' for f in EXAMPLES_PATH.iterdir()] labels = learn.dls.vocab v ='''

A recipe video

{0} ''' v_ls = ['''''', '''''', ''' ''', '''''', '''''', '''''' , '''''', '''''', '''''', '''''', '''''' ] def predict(img): img = PILImage.create(img) pred, pred_w_idx, probs = learn.predict(img) labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)} return labels_probs, v.format(v_ls[pred_w_idx]) demo = gr.Interface(predict, "image", [gr.outputs.Label(num_top_classes=3), "html"], examples= examples, title=title, description=description, article=article) demo.launch()