Spaces:
Runtime error
Runtime error
# AUTOGENERATED! DO NOT EDIT! File to edit: ../drive/MyDrive/Colab Notebooks/room classifier to app.ipynb. | |
# %% auto 0 | |
__all__ = ['learner', 'image', 'label', 'examples', 'intf', 'classify_image'] | |
# %% ../drive/MyDrive/Colab Notebooks/room classifier to app.ipynb 2 | |
import platform | |
import fastbook | |
import fastai | |
from fastai.vision.widgets import * | |
from fastai.callback.preds import load_learner | |
from fastai.vision.all import * | |
fastbook.setup_book() | |
# %% ../drive/MyDrive/Colab Notebooks/room classifier to app.ipynb 3 | |
if platform.system().lower() == "windows": | |
import pathlib | |
posix_path = pathlib.PosixPath | |
pathlib.PosixPath = pathlib.WindowsPath | |
learner = load_learner("room_classifier.pk1") | |
if platform.system().lower() == "windows": | |
pathlib.PosixPath = posix_path | |
# %% ../drive/MyDrive/Colab Notebooks/room classifier to app.ipynb 14 | |
def classify_image(img): | |
pred, idx, probs = learner.predict(img) | |
return dict(zip(learner.dls.vocab, map(float, probs))) | |
# %% ../drive/MyDrive/Colab Notebooks/room classifier to app.ipynb 16 | |
import gradio as gr | |
image = gr.inputs.Image(shape=(192, 192)) | |
label = gr.outputs.Label() | |
out_pl = widgets.Output() | |
examples = ["examples/test_bathroom.jfif", "examples/test_living_room.jfif", "examples/test_building.jfif"] | |
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) | |
intf.launch() | |