Spaces:
Build error
Build error
Download app.py from anon5/classifier-example: direct link, hf CLI and curl.
- Browser
- Download file 840 Bytes
-
https://huggingface.co/spaces/anon5/classifier-example/resolve/main/app.py
- Command line
-
hf download hf://spaces/anon5/classifier-example/app.py
-
curl -L -o app.py https://huggingface.co/spaces/anon5/classifier-example/resolve/main/app.py
840 Bytes
| import torch | |
| from transformers import pipeline | |
| import torch | |
| import gradio as gr | |
| with gr.Blocks() as demo: | |
| def submit(image): | |
| torch.backends.cuda.matmul.allow_tf32 = True | |
| torch.backends.cudnn.allow_tf32 = True | |
| pipe = pipeline("image-classification", model="./checkpoint-600") | |
| output = pipe(images=[image]) | |
| result = {} | |
| for index, item in enumerate(output[0]): | |
| result[item["label"]] = item["score"] | |
| return result | |
| with gr.Row(): | |
| with gr.Column(): | |
| image_input = gr.Image(label="Input image", type="filepath") | |
| with gr.Column(): | |
| label = gr.Label() | |
| submit_button = gr.Button(value="Submit", variant="primary") | |
| submit_button.click(submit, inputs=[image_input], outputs=label) | |
| demo.launch() |