Spaces:
Runtime error
Runtime error
from fastai.vision.all import * | |
import gradio as gr | |
from duckduckgo_search import ddg_images | |
from fastdownload import download_url | |
def find_image(img): | |
return L(ddg_images(img, max_results=1)).itemgot('image') | |
showcase_imgs = ["tomato", "apple", "lemon"] | |
def showcase(imgs): | |
for i in imgs: | |
url = find_image(i) | |
dest = f'./{i}.jpg' | |
download_url(url[0], dest, show_progress=False) | |
learner = load_learner("./model3.pk3") | |
labels = learner.dls.vocab | |
def predict(img): | |
img = PILImage.create(img) | |
pred, pred_idx, probs = learner.predict(img) | |
return {labels[i]: float(probs[i]) for i in range(len(labels))} | |
image = gr.inputs.Image(shape=(192, 192)) | |
label = gr.outputs.Label() | |
title = "Fruits and vegetables Classifier" | |
examples = ['tomato.jpg', 'lemon.jpg', 'apple.jpg'] | |
interface = gr.Interface(fn=predict, inputs=image, | |
outputs=label, examples=examples, title=title) | |
interface.launch(inline=False) | |