javierosello's picture
Update app.py
4edc1f4 verified
raw
history blame contribute delete
810 Bytes
from pathlib import Path
from time import sleep
from time import time
from fastai.vision.all import *
from fastai.vision.widgets import *
from fastbook import *
from fastcore.parallel import *
from fastdownload import download_url
from google.colab import drive
import gradio as gr
from huggingface_hub import from_pretrained_fastai, notebook_login, push_to_hub_fastai
import timm
from torchvision.models import resnet18
import os
learn = load_learner('model.pkl')
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))}
demo=gr.Interface(fn=predict, inputs=gr.Image(), outputs=gr.Label(num_top_classes=2)).launch(share=True)
if __name__ == "__main__":
demo.launch()