Spaces:
Sleeping
Sleeping
Download app.py from Anastasis/blip_img_captioning: direct link, hf CLI and curl.
- Browser
- Download file 670 Bytes
-
https://huggingface.co/spaces/Anastasis/blip_img_captioning/resolve/main/app.py
- Command line
-
hf download hf://spaces/Anastasis/blip_img_captioning/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Anastasis/blip_img_captioning/resolve/main/app.py
670 Bytes
| from transformers import BlipProcessor, BlipForConditionalGeneration | |
| import os | |
| import gradio as gr | |
| caption_model = 'Salesforce/blip-image-captioning-base' | |
| processor = BlipProcessor.from_pretrained(caption_model) | |
| model = BlipForConditionalGeneration.from_pretrained(caption_model) | |
| def launch(input): | |
| # proprocess text to prepare for the model | |
| inputs = processor(input, return_tensors="pt") | |
| output = model.generate(**inputs) | |
| cond_caption = processor.decode(output[0], skip_special_tokens=True) | |
| return cond_caption | |
| iface = gr.Interface(launch, | |
| inputs=gr.Image(type='pil'), | |
| outputs="text") | |
| # launch demo | |
| iface.launch() |