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) | |
def label_func(f): | |
return f.split("_")[0] | |
learner = load_learner("model3.pk3") | |
labels = learner.dls.vocab | |
def predict(image): | |
img = Image.fromarray(image) | |
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(num_top_classes=3) | |
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, enable_queue=True).launch() | |