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")# 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
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
# Load model and processor
|
| 7 |
+
@st.cache_resource
|
| 8 |
+
def load_model():
|
| 9 |
+
model_name = "your-huggingface-username/your-model-name"
|
| 10 |
+
processor = BlipProcessor.from_pretrained(model_name)
|
| 11 |
+
model = BlipForConditionalGeneration.from_pretrained(model_name)
|
| 12 |
+
return processor, model
|
| 13 |
+
|
| 14 |
+
processor, model = load_model()
|
| 15 |
+
|
| 16 |
+
# Streamlit UI
|
| 17 |
+
st.title("Cartoon Caption Generator 🖼️📜")
|
| 18 |
+
st.write("Upload a cartoon image and get a funny caption!")
|
| 19 |
+
|
| 20 |
+
uploaded_file = st.file_uploader("Upload a Cartoon Image", type=["jpg", "png", "jpeg"])
|
| 21 |
+
|
| 22 |
+
if uploaded_file is not None:
|
| 23 |
+
image = Image.open(uploaded_file).convert("RGB")
|
| 24 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 25 |
+
|
| 26 |
+
# Preprocess and generate caption
|
| 27 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 28 |
+
with torch.no_grad():
|
| 29 |
+
generated_ids = model.generate(**inputs)
|
| 30 |
+
caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 31 |
+
|
| 32 |
+
st.subheader("Generated Caption:")
|
| 33 |
+
st.write(f"💬 {caption}")
|