painters / app.py
viktor-kertanov's picture
painters app second attempt
3fb3192
raw
history blame contribute delete
623 Bytes
import gradio as gr
from fastai.vision.all import *
import os
learn = load_learner('painters_model.pkl')
painters_categories = list(learn.dls.vocab)
def classify_image(img):
'''Image classifications'''
pred, idx, probs = learn.predict(img)
return dict(zip(painters_categories, map(float, probs)))
image = gr.components.Image(shape=(192, 192))
label = gr.components.Label()
examples_dir = 'paintings_examples'
examples = [os.path.join(examples_dir, file) for file in os.listdir(examples_dir)]
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)