Image-Text-to-Text
Transformers
Safetensors
English
llava
captioning
conversational
4-bit precision
bitsandbytes
Instructions to use John6666/llama-joycaption-alpha-two-hf-llava-nf4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use John6666/llama-joycaption-alpha-two-hf-llava-nf4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="John6666/llama-joycaption-alpha-two-hf-llava-nf4") 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("John6666/llama-joycaption-alpha-two-hf-llava-nf4") model = AutoModelForMultimodalLM.from_pretrained("John6666/llama-joycaption-alpha-two-hf-llava-nf4", 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 John6666/llama-joycaption-alpha-two-hf-llava-nf4 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "John6666/llama-joycaption-alpha-two-hf-llava-nf4" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "John6666/llama-joycaption-alpha-two-hf-llava-nf4", "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/John6666/llama-joycaption-alpha-two-hf-llava-nf4
- SGLang
How to use John6666/llama-joycaption-alpha-two-hf-llava-nf4 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 "John6666/llama-joycaption-alpha-two-hf-llava-nf4" \ --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": "John6666/llama-joycaption-alpha-two-hf-llava-nf4", "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 "John6666/llama-joycaption-alpha-two-hf-llava-nf4" \ --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": "John6666/llama-joycaption-alpha-two-hf-llava-nf4", "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 John6666/llama-joycaption-alpha-two-hf-llava-nf4 with Docker Model Runner:
docker model run hf.co/John6666/llama-joycaption-alpha-two-hf-llava-nf4
Upload 3 files
Browse files- scripts/README.md +22 -17
scripts/README.md
CHANGED
|
@@ -14,23 +14,24 @@ This command will caption all the `.jpg` images in the specified directory using
|
|
| 14 |
|
| 15 |
## Command-Line Arguments
|
| 16 |
|
| 17 |
-
**Note**: You must specify either `--glob` or `--filelist` to provide images, and either `--prompt` or `--prompt-file` to provide a prompt for caption generation.
|
| 18 |
-
|
| 19 |
-
| Argument | Description | Default
|
| 20 |
-
| ------------------ | ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
| 21 |
-
| `--
|
| 22 |
-
| `--
|
| 23 |
-
| `--
|
| 24 |
-
| `--prompt
|
| 25 |
-
| `--
|
| 26 |
-
| `--
|
| 27 |
-
| `--
|
| 28 |
-
| `--
|
| 29 |
-
| `--top-
|
| 30 |
-
| `--
|
| 31 |
-
| `--
|
| 32 |
-
| `--
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
### Examples
|
|
@@ -40,6 +41,10 @@ This command will caption all the `.jpg` images in the specified directory using
|
|
| 40 |
```sh
|
| 41 |
./batch-caption.py --glob "images/*.png" --prompt "Write a descriptive caption for this image in a formal tone."
|
| 42 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
2. **Use a JSON file for prompts**
|
| 45 |
|
|
|
|
| 14 |
|
| 15 |
## Command-Line Arguments
|
| 16 |
|
| 17 |
+
**Note**: You must specify either `--glob` or `--filelist` or `--input` to provide images, and either `--prompt` or `--prompt-file` to provide a prompt for caption generation.
|
| 18 |
+
|
| 19 |
+
| Argument | Description | Default |
|
| 20 |
+
| ------------------ | ---------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
|
| 21 |
+
| `--input` | Input images | N/A |
|
| 22 |
+
| `--glob` | Glob pattern to find images | N/A |
|
| 23 |
+
| `--filelist` | File containing a list of images | N/A |
|
| 24 |
+
| `--prompt` | Prompt to use for caption generation | N/A |
|
| 25 |
+
| `--prompt-file` | JSON file containing prompts | N/A |
|
| 26 |
+
| `--batch-size` | Batch size for image processing | 1 |
|
| 27 |
+
| `--greedy` | Use greedy decoding instead of sampling | False |
|
| 28 |
+
| `--temperature` | Sampling temperature (used when not using greedy decoding) | 0.6 |
|
| 29 |
+
| `--top-p` | Top-p sampling value (nucleus sampling) | 0.9 |
|
| 30 |
+
| `--top-k` | Top-k sampling value | None |
|
| 31 |
+
| `--max-new-tokens` | Maximum length of the generated caption (in tokens) | 256 |
|
| 32 |
+
| `--num-workers` | Number of workers loading images in parallel | 4 |
|
| 33 |
+
| `--model` | Pre-trained model to use | [John6666/llama-joycaption-alpha-two-hf-llava-nf4](https://huggingface.co/John6666/llama-joycaption-alpha-two-hf-llava-nf4) |
|
| 34 |
+
| `--bf16` | Load model on torch.bfloat16 | False |
|
| 35 |
|
| 36 |
|
| 37 |
### Examples
|
|
|
|
| 41 |
```sh
|
| 42 |
./batch-caption.py --glob "images/*.png" --prompt "Write a descriptive caption for this image in a formal tone."
|
| 43 |
```
|
| 44 |
+
or
|
| 45 |
+
```sh
|
| 46 |
+
./batch-caption.py --input "images/dog.png" --prompt "Write a descriptive caption for this image in a formal tone."
|
| 47 |
+
```
|
| 48 |
|
| 49 |
2. **Use a JSON file for prompts**
|
| 50 |
|