Spaces:
Sleeping
Sleeping
import os | |
import random | |
import shutil | |
from pathlib import Path | |
import gradio as gr | |
from fastai.vision.all import load_learner, PILImage | |
examples = ['r0_43.jpg', | |
'r0_227.jpg', | |
'r1_51.jpg'] | |
# Load the learner | |
learn = load_learner('export(1).pkl') | |
# Define labels | |
labels = learn.dls.vocab | |
def predict(img): | |
img = PILImage.create(img) | |
pred, pred_idx, probs = learn.predict(img) | |
return {labels[i]: float(probs[i]) for i in range(len(labels))} | |
# Gradio interface | |
title = "Fruit-360" | |
description = "A ResNet18 feature extractor computer vision model to classify 24 classes of various fruits!" | |
article = "[Chris Olande.](https://github.com/Chrisolande)" | |
image = gr.Image() | |
label = gr.Label(num_top_classes=3) | |
gr.Interface(fn=predict, inputs=image, outputs=label, examples=examples, title=title, description=description, article=article).launch(share=True) | |