Spaces:
Runtime error
Runtime error
Download app.py from TANMIHA/mta-image-captioning: direct link, hf CLI and curl.
- Browser
- Download file 949 Bytes
-
https://huggingface.co/spaces/TANMIHA/mta-image-captioning/resolve/main/app.py
- Command line
-
hf download hf://spaces/TANMIHA/mta-image-captioning/app.py
-
curl -L -o app.py https://huggingface.co/spaces/TANMIHA/mta-image-captioning/resolve/main/app.py
949 Bytes
| import gradio as gr | |
| from PIL import Image | |
| from transformers import AutoProcessor, BlipForConditionalGeneration | |
| # Load model and processor | |
| processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base") | |
| model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base") | |
| def caption_image(input_image): | |
| raw_image = input_image.convert("RGB") | |
| inputs = processor(raw_image, return_tensors="pt") | |
| # Generate caption | |
| output = model.generate(**inputs, max_length=50) | |
| # Decode caption | |
| caption = processor.decode(output[0], skip_special_tokens=True) | |
| return caption | |
| iface = gr.Interface( | |
| fn=caption_image, | |
| inputs=gr.Image(type="pil"), | |
| outputs="text", | |
| title="MTA – AI-Powered Image Captioning", | |
| description="Upload an image and MTA v1.0 (Meaningful Tagging Assistant) will generate an intelligent caption using a vision-language AI model." | |
| ) | |
| iface.launch() | |