Instructions to use Nishthaaa/image_captioning with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Nishthaaa/image_captioning with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Nishthaaa/image_captioning")# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("Nishthaaa/image_captioning") model = AutoModelForMultimodalLM.from_pretrained("Nishthaaa/image_captioning", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Nishthaaa/image_captioning with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Nishthaaa/image_captioning" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Nishthaaa/image_captioning", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Nishthaaa/image_captioning
- SGLang
How to use Nishthaaa/image_captioning with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Nishthaaa/image_captioning" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Nishthaaa/image_captioning", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Nishthaaa/image_captioning" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Nishthaaa/image_captioning", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Nishthaaa/image_captioning with Docker Model Runner:
docker model run hf.co/Nishthaaa/image_captioning
Download app.py from Nishthaaa/image_captioning: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/Nishthaaa/image_captioning/resolve/main/app.py
- Command line
-
hf download hf://Nishthaaa/image_captioning/app.py
-
curl -L -o app.py https://huggingface.co/Nishthaaa/image_captioning/resolve/main/app.py
1.13 kB
| import streamlit as st | |
| from PIL import Image | |
| from transformers import BlipProcessor, BlipForConditionalGeneration | |
| import torch | |
| # Load model and processor | |
| def load_model(): | |
| model_name = "your-huggingface-username/your-model-name" | |
| processor = BlipProcessor.from_pretrained(model_name) | |
| model = BlipForConditionalGeneration.from_pretrained(model_name) | |
| return processor, model | |
| processor, model = load_model() | |
| # Streamlit UI | |
| st.title("Cartoon Caption Generator 🖼️📜") | |
| st.write("Upload a cartoon image and get a funny caption!") | |
| uploaded_file = st.file_uploader("Upload a Cartoon Image", type=["jpg", "png", "jpeg"]) | |
| if uploaded_file is not None: | |
| image = Image.open(uploaded_file).convert("RGB") | |
| st.image(image, caption="Uploaded Image", use_column_width=True) | |
| # Preprocess and generate caption | |
| inputs = processor(images=image, return_tensors="pt") | |
| with torch.no_grad(): | |
| generated_ids = model.generate(**inputs) | |
| caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0] | |
| st.subheader("Generated Caption:") | |
| st.write(f"💬 {caption}") | |