os_identify / app.py
Jesse Alter
add missing pieces
4604714
raw
history blame
1.81 kB
# AUTOGENERATED! DO NOT EDIT! File to edit: os_identify.ipynb.
# %% auto 0
__all__ = ['path', 'learn_inf', 'title', 'description', 'article', 'examples', 'interpretation', 'enable_queue', 'labels',
'predict']
# %% os_identify.ipynb 4
from fastai.vision.all import *
# from fastai.vision.widgets import *
import gradio as gr
# %% os_identify.ipynb 6
# btn_upload = widgets.FileUpload()
# btn_run = widgets.Button(description='Classify')
# btn_run.on_click(on_click_classify)
# %% os_identify.ipynb 7
# load the model
path = Path()
learn_inf = load_learner(path/'os_model.pkl')
# %% os_identify.ipynb 8
# out_pl = widgets.Output()
# out_pl.clear_output()
# lbl_pred = widgets.Label()
# %% os_identify.ipynb 9
# VBox([widgets.Label('Select your screencap!'),
# btn_upload, btn_run, out_pl, lbl_pred])
# %% os_identify.ipynb 10
title = "Operating System Screencap Classifier"
description = "A classifier trained on various operating system screenshots. For better results, use screenshots that clearly show unique UI elements. For best results, help me better a better dataset."
article="<p>article goes here</p>"
examples=['win95.jpg']
interpretation="default"
enable_queue=True
# %% os_identify.ipynb 11
labels = learn_inf.dls.vocab
def predict(img):
# img = PILImage.create(img)
pred,pred_idx,probs = learn_inf.predict(img)
return {labels[i]: float(probs[i]) for i in range(len(labels))}
gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch(share=True)
# gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3)).launch(share=True)