Spaces:
Runtime error
Runtime error
Download captioner.py from LIAOCJ/background-replacement: direct link, hf CLI and curl.
- Browser
- Download file 524 Bytes
-
https://huggingface.co/spaces/LIAOCJ/background-replacement/resolve/main/captioner.py
- Command line
-
hf download hf://spaces/LIAOCJ/background-replacement/captioner.py
-
curl -L -o captioner.py https://huggingface.co/spaces/LIAOCJ/background-replacement/resolve/main/captioner.py
524 Bytes
| from transformers import pipeline | |
| captioner = None | |
| PROMPT = "The main subject of this picture is a" | |
| def init(): | |
| global captioner | |
| print("Initializing captioner...") | |
| captioner = pipeline( | |
| "image-to-text", | |
| model="Salesforce/blip-image-captioning-base", | |
| prompt=PROMPT | |
| ) | |
| def derive_caption(image): | |
| result = captioner(image, max_new_tokens=20) | |
| raw_caption = result[0]["generated_text"] | |
| caption = raw_caption.lower().replace(PROMPT.lower(), "").strip() | |
| return caption | |