Instructions to use starvector/starvector-1b-im2svg with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use starvector/starvector-1b-im2svg with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="starvector/starvector-1b-im2svg", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("starvector/starvector-1b-im2svg", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use starvector/starvector-1b-im2svg with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "starvector/starvector-1b-im2svg" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "starvector/starvector-1b-im2svg", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/starvector/starvector-1b-im2svg
- SGLang
How to use starvector/starvector-1b-im2svg 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 "starvector/starvector-1b-im2svg" \ --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": "starvector/starvector-1b-im2svg", "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 "starvector/starvector-1b-im2svg" \ --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": "starvector/starvector-1b-im2svg", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use starvector/starvector-1b-im2svg with Docker Model Runner:
docker model run hf.co/starvector/starvector-1b-im2svg
| from transformers.processing_utils import ProcessorMixin | |
| from torchvision import transforms | |
| from torchvision.transforms.functional import InterpolationMode, pad | |
| from transformers.feature_extraction_sequence_utils import BatchFeature | |
| class SimpleStarVectorProcessor(ProcessorMixin): | |
| attributes = ["tokenizer"] # Only include tokenizer in attributes | |
| valid_kwargs = ["size", "mean", "std"] # Add other parameters as valid kwargs | |
| image_processor_class = "AutoImageProcessor" | |
| tokenizer_class = "AutoTokenizer" | |
| def __init__(self, | |
| tokenizer=None, # Make tokenizer the first argument | |
| size=224, | |
| mean=None, | |
| std=None, | |
| **kwargs, | |
| ): | |
| if mean is None: | |
| mean = (0.48145466, 0.4578275, 0.40821073) | |
| if std is None: | |
| std = (0.26862954, 0.26130258, 0.27577711) | |
| # Store these as instance variables | |
| self.mean = mean | |
| self.std = std | |
| self.size = size | |
| self.normalize = transforms.Normalize(mean=mean, std=std) | |
| self.transform = transforms.Compose([ | |
| transforms.Lambda(lambda img: img.convert("RGB") if img.mode == "RGBA" else img), | |
| transforms.Lambda(lambda img: self._pad_to_square(img)), | |
| transforms.Resize(size, interpolation=InterpolationMode.BICUBIC), | |
| transforms.ToTensor(), | |
| self.normalize | |
| ]) | |
| # Initialize parent class with tokenizer | |
| super().__init__(tokenizer=tokenizer) | |
| def __call__(self, images=None, text=None, **kwargs) -> BatchFeature: | |
| """ | |
| Process images and/or text inputs. | |
| Args: | |
| images: Optional image input(s) | |
| text: Optional text input(s) | |
| **kwargs: Additional arguments | |
| """ | |
| if images is None and text is None: | |
| raise ValueError("You have to specify at least one of `images` or `text`.") | |
| image_inputs = {} | |
| if images is not None: | |
| if isinstance(images, (list, tuple)): | |
| images_ = [self.transform(img) for img in images] | |
| else: | |
| images_ = self.transform(images) | |
| image_inputs = {"pixel_values": images_} | |
| text_inputs = {} | |
| if text is not None: | |
| text_inputs = self.tokenizer(text, **kwargs) | |
| return BatchFeature(data={**text_inputs, **image_inputs}) | |
| def _pad_to_square(self, img): | |
| # Calculate padding to make the image square | |
| width, height = img.size | |
| max_dim = max(width, height) | |
| padding = [(max_dim - width) // 2, (max_dim - height) // 2] | |
| padding += [max_dim - width - padding[0], max_dim - height - padding[1]] | |
| return pad(img, padding, fill=255) # Assuming white padding | |
| AutoProcessor.register(SimpleStarVectorProcessor, SimpleStarVectorProcessor) | |