Download app.py from archietram/Multiple_Object_Detector_PASCAL_2007: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/archietram/Multiple_Object_Detector_PASCAL_2007/resolve/main/app.py
- Command line
-
hf download hf://spaces/archietram/Multiple_Object_Detector_PASCAL_2007/app.py
-
curl -L -o app.py https://huggingface.co/spaces/archietram/Multiple_Object_Detector_PASCAL_2007/resolve/main/app.py
1.1 kB
| from fastai.vision.all import * | |
| import gradio as gr | |
| def get_x(): return _ | |
| def get_y(): return _ | |
| learn = load_learner("export.pkl") | |
| labels = learn.dls.vocab | |
| def infer(img): | |
| img = PILImage.create(img) | |
| _pred, _pred_w_idx, probs = learn.predict(img) | |
| # gradio doesn't support tensors, so converting to float | |
| labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)} | |
| return labels_probs | |
| # get the inputs | |
| inputs = gr.inputs.Image(shape=(192, 192)) | |
| # the app outputs two segmented images | |
| outputs = gr.outputs.Label(num_top_classes=3) | |
| EXAMPLES_PATH = Path('./examples') | |
| examples = [f'{EXAMPLES_PATH}/{f.name}' for f in EXAMPLES_PATH.iterdir()] | |
| # it's good practice to pass examples, description and a title to guide users | |
| title = 'Multiple Object Detector' | |
| description = 'This app detects objects that appear in the image' | |
| article = "Author: <a href=\"https://huggingface.co/archietram\">Archie Tram</a>. " | |
| intf = gr.Interface(fn=infer, inputs=inputs, outputs=outputs, examples=examples, title=title, description=description, article=article) | |
| intf.launch(inline=False) | |