Download app.py from Trian123/Project: direct link, hf CLI and curl.
- Browser
- Download file 797 Bytes
-
https://huggingface.co/spaces/Trian123/Project/resolve/main/app.py
- Command line
-
hf download hf://spaces/Trian123/Project/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Trian123/Project/resolve/main/app.py
797 Bytes
| from transformers import BlipProcessor, BlipForConditionalGeneration | |
| import gradio as gr | |
| # Load processor and model | |
| processor = BlipProcessor.from_pretrained( | |
| "Salesforce/blip-image-captioning-base" | |
| ) | |
| model = BlipForConditionalGeneration.from_pretrained( | |
| "Salesforce/blip-image-captioning-base" | |
| ) | |
| # Function | |
| def generate_caption(image): | |
| inputs = processor(images=image, return_tensors="pt") | |
| output = model.generate(**inputs) | |
| caption = processor.decode( | |
| output[0], | |
| skip_special_tokens=True | |
| ) | |
| return caption | |
| # Gradio interface | |
| demo = gr.Interface( | |
| fn=generate_caption, | |
| inputs=gr.Image(type="pil"), | |
| outputs="text", | |
| title="AI Image Caption Generator", | |
| description="Upload image and AI describes it." | |
| ) | |
| # Launch app | |
| demo.launch() |