Spaces:
Runtime error
Runtime error
Download app.py from editoraapp/test-zero-shot: direct link, hf CLI and curl.
- Browser
- Download file 650 Bytes
-
https://huggingface.co/spaces/editoraapp/test-zero-shot/resolve/main/app.py
- Command line
-
hf download hf://spaces/editoraapp/test-zero-shot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/editoraapp/test-zero-shot/resolve/main/app.py
650 Bytes
| import gradio as gr | |
| from transformers import pipeline | |
| checkpoint = "openai/clip-vit-large-patch14" | |
| detector = pipeline(model=checkpoint, task="zero-shot-image-classification") | |
| def classify(img, candidates): | |
| labels = candidates.split(sep=",") | |
| predictions = detector(img, candidate_labels=labels) | |
| return predictions | |
| with gr.Blocks() as iface: | |
| image = gr.Image(type="pil", label="Image") | |
| candidates = gr.Textbox(label="Candidates") | |
| predictions = gr.Textbox(label="Predictions") | |
| btn = gr.Button("Classify") | |
| btn.click(fn=classify, inputs=[image, candidates], outputs=predictions, api_name="classify") | |
| iface.launch() |