Download app.py from bwuzhang/blip-api: direct link, hf CLI and curl.
- Browser
- Download file 619 Bytes
-
https://huggingface.co/spaces/bwuzhang/blip-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/bwuzhang/blip-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/bwuzhang/blip-api/resolve/main/app.py
619 Bytes
| from PIL import Image | |
| import requests | |
| import gradio as gr | |
| from transformers import BlipProcessor, BlipForConditionalGeneration | |
| model_id = "Salesforce/blip-image-captioning-base" | |
| model = BlipForConditionalGeneration.from_pretrained(model_id) | |
| processor = BlipProcessor.from_pretrained(model_id) | |
| ## | |
| def launch(input): | |
| image = Image.open(requests.get(input, stream=True).raw).convert('RGB') | |
| inputs = processor(image, return_tensors="pt") | |
| out = model.generate(**inputs) | |
| return processor.decode(out[0], skip_special_tokens=True) | |
| iface = gr.Interface(launch, inputs="text", outputs="text") | |
| iface.launch() |