Instructions to use remyxai/SpaceMantis with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use remyxai/SpaceMantis with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="remyxai/SpaceMantis") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("remyxai/SpaceMantis") model = AutoModelForMultimodalLM.from_pretrained("remyxai/SpaceMantis", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use remyxai/SpaceMantis with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "remyxai/SpaceMantis" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "remyxai/SpaceMantis", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/remyxai/SpaceMantis
- SGLang
How to use remyxai/SpaceMantis 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 "remyxai/SpaceMantis" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "remyxai/SpaceMantis", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "remyxai/SpaceMantis" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "remyxai/SpaceMantis", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use remyxai/SpaceMantis with Docker Model Runner:
docker model run hf.co/remyxai/SpaceMantis
Update README.md
Browse files
README.md
CHANGED
|
@@ -28,6 +28,43 @@ With a pipeline of expert models, we can infer spatial relationships between obj
|
|
| 28 |
- **Developed by:** remyx.ai
|
| 29 |
- **Model type:** MultiModal Model, Vision Language Model, Llama 3
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
### Model Sources
|
| 32 |
- **Dataset:** [SpaceLLaVA](https://huggingface.co/datasets/remyxai/vqasynth_spacellava)
|
| 33 |
- **Repository:** [VQASynth](https://github.com/remyxai/VQASynth/tree/main)
|
|
|
|
| 28 |
- **Developed by:** remyx.ai
|
| 29 |
- **Model type:** MultiModal Model, Vision Language Model, Llama 3
|
| 30 |
|
| 31 |
+
## Quick Start
|
| 32 |
+
|
| 33 |
+
To run SpaceMantis, follow these steps:
|
| 34 |
+
|
| 35 |
+
```python
|
| 36 |
+
import torch
|
| 37 |
+
from PIL import Image
|
| 38 |
+
from models.mllava import MLlavaProcessor, LlavaForConditionalGeneration, chat_mllava
|
| 39 |
+
|
| 40 |
+
# Load the model and processor
|
| 41 |
+
attn_implementation = None # or "flash_attention_2"
|
| 42 |
+
processor = MLlavaProcessor.from_pretrained("remyxai/SpaceMantis")
|
| 43 |
+
model = LlavaForConditionalGeneration.from_pretrained("remyxai/SpaceMantis", device_map="cuda", torch_dtype=torch.float16, attn_implementation=attn_implementation)
|
| 44 |
+
|
| 45 |
+
generation_kwargs = {
|
| 46 |
+
"max_new_tokens": 1024,
|
| 47 |
+
"num_beams": 1,
|
| 48 |
+
"do_sample": False
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
# Function to run inference
|
| 52 |
+
def run_inference(image_path, content):
|
| 53 |
+
# Load the image
|
| 54 |
+
image = Image.open(image_path).convert("RGB")
|
| 55 |
+
# Convert the image to base64
|
| 56 |
+
images = [image]
|
| 57 |
+
# Run the inference
|
| 58 |
+
response, history = chat_mllava(content, images, model, processor, **generation_kwargs)
|
| 59 |
+
return response
|
| 60 |
+
|
| 61 |
+
# Example usage
|
| 62 |
+
image_path = "path/to/your/image.jpg"
|
| 63 |
+
content = "Your question here."
|
| 64 |
+
response = run_inference(image_path, content)
|
| 65 |
+
print("Response:", response)
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
### Model Sources
|
| 69 |
- **Dataset:** [SpaceLLaVA](https://huggingface.co/datasets/remyxai/vqasynth_spacellava)
|
| 70 |
- **Repository:** [VQASynth](https://github.com/remyxai/VQASynth/tree/main)
|