Spaces:
Sleeping
Sleeping
Download app.py from Flake56/AI-Image-Caption: direct link, hf CLI and curl.
- Browser
- Download file 785 Bytes
-
https://huggingface.co/spaces/Flake56/AI-Image-Caption/resolve/main/app.py
- Command line
-
hf download hf://spaces/Flake56/AI-Image-Caption/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Flake56/AI-Image-Caption/resolve/main/app.py
785 Bytes
| import gradio as gr | |
| from transformers import BlipProcessor, BlipForConditionalGeneration | |
| from PIL import Image | |
| import requests | |
| model_name = "Salesforce/blip-image-captioning-base" | |
| processor = BlipProcessor.from_pretrained(model_name) | |
| model = BlipForConditionalGeneration.from_pretrained(model_name) | |
| def generate_caption(image): | |
| image = image.convert("RGB") | |
| inputs = processor(image, return_tensors="pt") | |
| out = model.generate(**inputs) | |
| caption = processor.decode(out[0], skip_special_tokens=True) | |
| return caption | |
| iface = gr.Interface( | |
| fn=generate_caption, | |
| inputs=gr.Image(type="pil"), | |
| outputs="text", | |
| title="🖼️ AI Image Captioning", | |
| description="Upload an image, and the AI will generate a descriptive caption!" | |
| ) | |
| iface.launch(share=True) |