Instructions to use kumararvindibs/ibs_imgToTextGeneration with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use kumararvindibs/ibs_imgToTextGeneration with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="kumararvindibs/ibs_imgToTextGeneration")# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("kumararvindibs/ibs_imgToTextGeneration") model = AutoModelForMultimodalLM.from_pretrained("kumararvindibs/ibs_imgToTextGeneration", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use kumararvindibs/ibs_imgToTextGeneration with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "kumararvindibs/ibs_imgToTextGeneration" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kumararvindibs/ibs_imgToTextGeneration", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/kumararvindibs/ibs_imgToTextGeneration
- SGLang
How to use kumararvindibs/ibs_imgToTextGeneration 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 "kumararvindibs/ibs_imgToTextGeneration" \ --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": "kumararvindibs/ibs_imgToTextGeneration", "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 "kumararvindibs/ibs_imgToTextGeneration" \ --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": "kumararvindibs/ibs_imgToTextGeneration", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use kumararvindibs/ibs_imgToTextGeneration with Docker Model Runner:
docker model run hf.co/kumararvindibs/ibs_imgToTextGeneration
File size: 3,706 Bytes
ed105db 589bc03 74b1841 ed105db b29140f ed105db cec4136 5533337 74b1841 ed105db 74b1841 ed105db 74b1841 ed105db 74b1841 ed105db 043d595 ed105db cc479e4 043d595 ed105db 589bc03 74b1841 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | import requests
from typing import Dict, Any
from PIL import Image
import torch
import base64
import io
from transformers import BlipForConditionalGeneration, BlipProcessor
import logging
from io import BytesIO
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
# Configure logging
logging.basicConfig(level=logging.DEBUG)
# Configure logging
logging.basicConfig(level=logging.ERROR)
# Configure logging
logging.basicConfig(level=logging.WARNING)
class EndpointHandler():
def __init__(self, path=""):
self.processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
self.model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large").to(device)
self.model.eval()
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
logging.error(f"----------This is an error message {str(data)}")
input_data = data.get("inputs", {})
logging.warning(f"------input_data-- {str(input_data)}")
encoded_images = input_data.get("url")
print("url---",encoded_images)
# Convert image to bytes
# image = Image.open(encoded_images[0])
#url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
# Send a GET request to the URL to get the image data
response = requests.get(encoded_images)
# Read the image data from the response
image_data = BytesIO(response.content)
#image_bytes = image.tobytes()
# img = Image.open(image_data)
#print("testing img--------------", img)
#logging.warning(f"---image_bytes----- {str(image_bytes)}")
# Encode image bytes as base64
#image_base64 = base64.b64encode(image_bytes).decode("utf-8")
#logging.warning(f"---encoded_images----- {str(image_base64)}")
# print("000--------", image_base64)
if not encoded_images:
logging.warning(f"---encoded_images--not provided in if block--- {str(encoded_images)}")
return {"captions": [], "error": "No images provided"}
try:
logging.warning(f"---encoded_images-- provided in try block--- {str(encoded_images)}")
byteImgIO = io.BytesIO()
byteImg = Image.open(image_data)
print("testing img---byteImg-----------", byteImg)
byteImg.save(byteImgIO, "PNG")
byteImgIO.seek(0)
byteImg = byteImgIO.read()
# Non test code
dataBytesIO = io.BytesIO(byteImg)
raw_images =[Image.open(dataBytesIO)]
logging.warning(f"----raw_images----0--- {str(raw_images)}")
# Check if any images were successfully decoded
if not raw_images:
print("No valid images found.")
processed_inputs = [
self.processor(image, return_tensors="pt") for image in zip(raw_images)
]
processed_inputs = {
"pixel_values": torch.cat([inp["pixel_values"] for inp in processed_inputs], dim=0).to(device),
"max_new_tokens":40
}
with torch.no_grad():
out = self.model.generate(**processed_inputs)
captions = self.processor.batch_decode(out, skip_special_tokens=True)
logging.warning(f"----captions---- {str(captions)}")
print("caption is here-------",captions)
return {"captions": captions}
except Exception as e:
print(f"Error during processing: {str(e)}")
logging.error(f"Error during processing: ----------------{str(e)}")
return {"captions": [], "error": str(e)} |