File size: 837 Bytes
7eabe60 a6331ab c4f0b8c a6331ab c4f0b8c 602a938 c4f0b8c 91b6200 8b45d4a 45c0971 685a73b 45c0971 91b6200 8b45d4a 91b6200 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
from fastai.vision.all import *
import gradio as gr
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))}
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
img = gr.Image(height=500, sources=["upload"])
examples = gr.Examples([
["./imgs/dali2.jpeg"],
["./imgs/dali3.jpeg"],
["./imgs/dali4.jpeg"],
["./imgs/dali5.jpeg"],
["./imgs/dali6.jpeg"],
], inputs=img)
with gr.Row():
clear_btn = gr.ClearButton(value="Clear")
submit_btn = gr.Button("Predict")
output = gr.Label(num_top_classes=2, label="Labels")
submit_btn.click(predict, img, output)
clear_btn.add(img)
demo.launch() |