Spaces:
Runtime error
Runtime error
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 ='''<!DOCTYPE html> | |
<html> | |
<body> | |
<h1>A recipe video</h1> | |
{0} | |
</body> | |
</html> ''' | |
v_ls = ['''<iframe width="956" height="240" src="https://www.youtube.com/embed/53Kj_dpBYzo" title="How to Make Ethiopian Food: Yetsom Beyaynetu | α¨α α α α«ααα± α₯α΅α«α" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>''', | |
'''<iframe width="956" height="240" src="https://www.youtube.com/embed/Hw9K9Q9Q_0M" title="Chechebsa (Spicy Flat Bread) | Ethiopian/Eritrean Food BY HabeshChef" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>''', | |
''' <iframe width="956" height="240" src="https://www.youtube.com/embed/zi4AT6uYKUs" title="How To Make Spicy Ethiopian Chicken Stew: Doro Wat" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>''', | |
'''<iframe width="956" height="240" src="https://www.youtube.com/embed/V2fuMDmjqbc" title="Best Ethiopian Breakfast Food: Firfir Recipe (αααα α α°α«α )" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>''', | |
'''<iframe width="956" height="240" src="https://www.youtube.com/embed/9iFMR3299BY" title="Genfo (Ethiopian style porridge)" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>''', | |
'''<iframe width="956" height="240" src="https://www.youtube.com/embed/XtS1uzHGBYQ" title="Ethiopian Food EASY KIKIL Recipe α¨α α α α α°α«α | Amena and Elias" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>''' , | |
'''<iframe width="956" height="240" src="https://www.youtube.com/embed/-xFR_daRIyw" title="Get a Taste Of Ethiopia: Kitfo with Woinee Mariam | Food Network" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>''', | |
'''<iframe width="956" height="240" src="https://www.youtube.com/embed/SFEu7JcQsis" title="Letβs cook Ethiopian Shekla Tibs! π₯" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>''', | |
'''<iframe width="956" height="240" src="https://www.youtube.com/embed/_W_J6wNq3nI" title="LET'S MAKE SHIRO TOGETHER AT HOME Vlogmas Day 22" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>''', | |
'''<iframe width="956" height="240" src="https://www.youtube.com/embed/7kDe2yBgB1I" title="α£α αα α¨ α₯αα α α°α«α | Traditional Tigrayan Tihlo Recipe | Ethiopian Food" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>''', | |
'''<iframe width="956" height="240" src="https://www.youtube.com/embed/Qex-uPtbUD0" title="FEEDING RAW MEAT TO GERMAN DIASPORA" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>''' | |
] | |
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() |