CoolFace
Apppublic

ArtisticDL/bear_classifier

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
app.py58 linesDownload Raw Back to root
1# AUTOGENERATED! DO NOT EDIT! File to edit: Untitled.ipynb.2 3# %% auto 04__all__ = [5    "pk_fil",6    "learn_inf",7    "labels",8    "title",9    "description",10    "examples",11    "iface",12    "predict",13]14 15# %% Untitled.ipynb 216from fastbook import *17import pathlib18from fastai.vision.widgets import *19 20plt = platform.system()21if plt == "Linux":22    pathlib.WindowsPath = pathlib.PosixPath23# %% Untitled.ipynb 4324pk_fil = "./model.pkl"25 26 27# %% Untitled.ipynb 4428learn_inf = load_learner(pk_fil)29 30# %% Untitled.ipynb 6531import gradio as gr32 33# %% Untitled.ipynb 6634labels = learn_inf.dls.vocab35 36 37def predict(img):38    img = PILImage.create(img)39    pred, pred_idx, probs = learn_inf.predict(img)40    return {labels[i]: float(probs[i]) for i in range(len(labels))}41 42 43# %% Untitled.ipynb 7044title = "Bear Classifier"45description = "A bear classifier. Created as a demo for Gradio and HuggingFace Spaces."46 47# %% Untitled.ipynb 7148examples = ["./grizzly.jpg"]49 50# %% Untitled.ipynb 7451iface = gr.Interface(52    fn=predict,53    inputs=gr.Image(type="pil"),  # No shape parameter, 'pil' type returns a PIL Image54    outputs=gr.Label(num_top_classes=3),55    description=description,56    examples=examples,57).launch(share=True)58