import gradio as gr from fastai.vision.widgets import PILImage from huggingface_hub import from_pretrained_fastai hf_learn = from_pretrained_fastai("admarhi/towerificator") labels = hf_learn.dls.vocab pisa_dest = 'pisa.jpg' burj_dest = 'burj.jpg' eiffel_dest = 'eiffel.jpg' def predict(img): img = PILImage.create(img) pred,pred_idx,probs = hf_learn.predict(img) return {labels[i]: float(probs[i]) for i in range(len(labels))} title = "Towerificator 3000" desc = '''Introducing the Towerificator 3000 – the AI-powered marvel that can tell a tower from a flower, a skyscraper from a skysquawker, and a spire from a satire! Our image classifier is so advanced, it can spot a tower in a haystack or even distinguish between a castle tower and a tower of pizza. Equipped with the latest in artificial intelligence, our Towerificator has a PhD in Towerology (the study of towers, obviously) and a black belt in "Tower-fu." It can identify towers faster than you can say, "Why did the tower apply for a job? Because it needed a high-rise!" So, if you've ever looked at a skyline and thought, "What in the name of pixelated panoramas is that?" – fear not! The Towerificator 3000 is here to sort your towers from your troubles, all while sprinkling a dash of wit on your image classification journey. Because when it comes to towers, our AI doesn't just classify; it towerfies!''' iface = gr.Interface(fn=predict, inputs=gr.Image(), outputs=gr.Label(num_top_classes=6), examples = [burj_dest, pisa_dest, eiffel_dest], title=title, description=desc) iface.launch()