> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-hi/vision-models/llava-vision-language.md).

# LLaVA

Clore.ai पर LLaVA विज़न-लैंग्वेज मॉडल के साथ छवियों से चैट करें

LLaVA के साथ छवियों पर चैट करें - ओपन-सोर्स GPT-4V विकल्प।

{% hint style="success" %}
सभी उदाहरण GPU सर्वरों पर चलाए जा सकते हैं, जिन्हें किराए पर लिया गया है [CLORE.AI मार्केटप्लेस](https://clore.ai/marketplace).
{% endhint %}

## CLORE.AI पर किराए पर लेना

1. विज़िट करें [CLORE.AI मार्केटप्लेस](https://clore.ai/marketplace)
2. GPU प्रकार, VRAM और कीमत के अनुसार फ़िल्टर करें
3. चुनें **ऑन-डिमांड** (स्थिर दर) या **स्पॉट** (बोली मूल्य)
4. अपना ऑर्डर कॉन्फ़िगर करें:
   * Docker इमेज चुनें
   * पोर्ट सेट करें (SSH के लिए TCP, वेब UI के लिए HTTP)
   * यदि आवश्यक हो तो environment variables जोड़ें
   * स्टार्टअप कमांड दर्ज करें
5. भुगतान चुनें: **CLORE**, **BTC**या **USDT/USDC**
6. ऑर्डर बनाएं और डिप्लॉयमेंट की प्रतीक्षा करें

### अपने सर्वर तक पहुँचें

* कनेक्शन विवरण यहाँ खोजें **मेरे ऑर्डर**
* वेब इंटरफ़ेस: HTTP पोर्ट URL का उपयोग करें
* SSH: `ssh -p <port> root@<proxy-address>`

## LLaVA क्या है?

LLaVA (Large Language and Vision Assistant) यह कर सकता है:

* छवियों को समझना और उनका वर्णन करना
* दृश्य सामग्री के बारे में प्रश्नों का उत्तर देना
* चार्ट, आरेख, स्क्रीनशॉट का विश्लेषण करना
* OCR और दस्तावेज़ समझ

## मॉडल वेरिएंट

| मॉडल          | आकार  | VRAM   | गुणवत्ता  |
| ------------- | ----- | ------ | --------- |
| LLaVA-1.5-7B  | 7B    | 8GB    | अच्छा     |
| LLaVA-1.5-13B | 13B   | 16GB   | बेहतर     |
| LLaVA-1.6-34B | 34B   | 40GB   | सर्वोत्तम |
| LLaVA-NeXT    | 7-34B | 8-40GB | नवीनतम    |

## त्वरित डिप्लॉय

**Docker इमेज:**

```
pytorch/pytorch:2.11.0-cuda12.8-cudnn9-devel
```

**पोर्ट:**

```
22/tcp
8000/http
```

**कमांड:**

```bash
pip install llava torch transformers accelerate gradio && \
python -m llava.serve.cli --model-path liuhaotian/llava-v1.5-7b --load-4bit
```

## अपनी सेवा तक पहुँचना

डिप्लॉयमेंट के बाद, अपना `http_pub` URL यहाँ **मेरे ऑर्डर**:

1. पर जाएँ **मेरे ऑर्डर** पेज
2. अपने ऑर्डर पर क्लिक करें
3. खोजें `http_pub` URL (उदा., `abc123.clorecloud.net`)

उपयोग करें `https://YOUR_HTTP_PUB_URL` की बजाय `localhost` नीचे दिए गए उदाहरणों में।

## इंस्टॉलेशन

```bash
git clone https://github.com/haotian-liu/LLaVA.git
cd LLaVA
pip install -e .
pip install flash-attn --no-build-isolation
```

## मूल उपयोग

### Python API

```python
from llava.model.builder import load_pretrained_model
from llava.mm_utils import get_model_name_from_path
from llava.eval.run_llava import eval_model
from PIL import Image

model_path = "liuhaotian/llava-v1.5-7b"
tokenizer, model, image_processor, context_len = load_pretrained_model(
    model_path=model_path,
    model_base=None,
    model_name=get_model_name_from_path(model_path)
)

# सरल अनुमान
args = type('Args', (), {
    "model_path": model_path,
    "model_base": None,
    "model_name": get_model_name_from_path(model_path),
    "query": "इस छवि का विस्तार से वर्णन करें",
    "conv_mode": None,
    "image_file": "photo.jpg",
    "sep": ",",
    "temperature": 0.2,
    "top_p": None,
    "num_beams": 1,
    "max_new_tokens": 512
})()

output = eval_model(args)
print(output)
```

### Transformers का उपयोग

```python
from transformers import LlavaNextProcessor, LlavaNextForConditionalGeneration
import torch
from PIL import Image

processor = LlavaNextProcessor.from_pretrained("llava-hf/llava-v1.6-mistral-7b-hf")
model = LlavaNextForConditionalGeneration.from_pretrained(
    "llava-hf/llava-v1.6-mistral-7b-hf",
    torch_dtype=torch.float16,
    device_map="auto"
)

# छवि लोड करें
image = Image.open("photo.jpg")

# बातचीत बनाएँ
conversation = [
    {
        "role": "user",
        "content": [
            {"type": "image"},
            {"type": "text", "text": "इस छवि में क्या दिखाया गया है?"}
        ]
    }
]

prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
inputs = processor(prompt, image, return_tensors="pt").to("cuda")

output = model.generate(**inputs, max_new_tokens=200)
response = processor.decode(output[0], skip_special_tokens=True)
print(response)
```

## Ollama एकीकरण (अनुशंसित)

CLORE.AI पर LLaVA चलाने का सबसे आसान तरीका:

```bash
# Ollama इंस्टॉल करें
curl -fsSL https://ollama.com/install.sh | sh

# LLaVA मॉडल पुल करें
ollama pull llava:7b

# छवि के साथ चलाएँ (CLI)
ollama run llava:7b "इस छवि का वर्णन करें: /path/to/image.jpg"
```

### Ollama के माध्यम से LLaVA API

{% hint style="warning" %}
**महत्वपूर्ण:** LLaVA विज़न काम करता है **केवल** के माध्यम से `/api/generate` एंडपॉइंट के `images` पैरामीटर के साथ। `/api/chat` और OpenAI-संगत एंडपॉइंट **नहीं** LLaVA के साथ छवियों का समर्थन करते हैं।
{% endhint %}

#### कार्य करने की विधि: /api/generate

```bash
# पहले छवि को base64 में एन्कोड करें
BASE64_IMAGE=$(base64 -i photo.jpg | tr -d '\n')

# विज़न अनुरोध भेजें
curl https://your-http-pub.clorecloud.net/api/generate -d "{
  \"model\": \"llava:7b\",
  \"prompt\": \"इस छवि में आप क्या देखते हैं? विस्तार से वर्णन करें।\",
  \"images\": [\"$BASE64_IMAGE\"],
  \"stream\": false
}"
```

प्रतिक्रिया:

```json
{
  "model": "llava:7b",
  "response": "छवि में पहाड़ों के ऊपर एक सुंदर सूर्यास्त दिख रहा है...",
  "done": true
}
```

#### काम नहीं करता: /api/chat (विज़न के लिए null लौटाता है)

```bash
# यह विज़न क्वेरी के लिए काम नहीं करता:
curl https://your-http-pub.clorecloud.net/api/chat -d '{
  "model": "llava:7b",
  "messages": [{"role": "user", "content": "वर्णन करें", "images": ["..."]}]
}'
# छवि-संबंधित प्रतिक्रियाओं के लिए null लौटाता है
```

### Ollama के साथ Python

```python
import requests
import base64

def encode_image(image_path):
    with open(image_path, "rb") as f:
        return base64.b64encode(f.read()).decode()

# विज़न के लिए /api/generate का उपयोग करें (/api/chat नहीं!)
response = requests.post(
    "https://your-http-pub.clorecloud.net/api/generate",
    json={
        "model": "llava:7b",
        "prompt": "इस छवि में आप क्या देखते हैं?",
        "images": [encode_image("photo.jpg")],
        "stream": False
    }
)

print(response.json()["response"])
```

### पूरा कार्यशील उदाहरण

```python
import requests
import base64
import sys

def analyze_image(ollama_url, image_path, question):
    """Ollama के माध्यम से LLaVA का उपयोग करके छवि का विश्लेषण करें"""

    # छवि एन्कोड करें
    with open(image_path, "rb") as f:
        image_base64 = base64.b64encode(f.read()).decode()

    # /api/generate का उपयोग करें (विज़न के लिए यही एकमात्र काम करने वाला एंडपॉइंट है)
    response = requests.post(
        f"{ollama_url}/api/generate",
        json={
            "model": "llava:7b",
            "prompt": question,
            "images": [image_base64],
            "stream": False
        }
    )

    return response.json()["response"]

# उपयोग
url = "https://your-http-pub.clorecloud.net"
result = analyze_image(url, "photo.jpg", "इस छवि का विस्तार से वर्णन करें")
print(result)
```

## उपयोग के मामले

### छवि विवरण

```python
prompt = "इस छवि का विस्तार से वर्णन करें, जिसमें रंग, वस्तुएँ, और वातावरण शामिल हों।"
```

### OCR / पाठ निष्कर्षण

```python
prompt = "इस छवि में दिखाई देने वाला सभी पाठ निकालें। इसे स्पष्ट रूप से प्रारूपित करें।"
```

### चार्ट विश्लेषण

```python
prompt = "इस चार्ट का विश्लेषण करें। प्रमुख रुझान और अंतर्दृष्टियाँ क्या हैं?"
```

### स्क्रीनशॉट से कोड

```python
prompt = "इस स्क्रीनशॉट में दिखाए गए कोड को निकालें। केवल कोड प्रदान करें।"
```

### ऑब्जेक्ट डिटेक्शन

```python
prompt = "इस छवि में दिखाई देने वाली सभी वस्तुओं को उनकी अनुमानित स्थितियों के साथ सूचीबद्ध करें।"
```

## Gradio इंटरफ़ेस

```python
import gradio as gr
from transformers import LlavaNextProcessor, LlavaNextForConditionalGeneration
import torch

processor = LlavaNextProcessor.from_pretrained("llava-hf/llava-v1.6-mistral-7b-hf")
model = LlavaNextForConditionalGeneration.from_pretrained(
    "llava-hf/llava-v1.6-mistral-7b-hf",
    torch_dtype=torch.float16,
    device_map="auto"
)

def analyze_image(image, question):
    conversation = [
        {
            "role": "user",
            "content": [
                {"type": "image"},
                {"type": "text", "text": question}
            ]
        }
    ]

    prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
    inputs = processor(prompt, image, return_tensors="pt").to("cuda")

    output = model.generate(**inputs, max_new_tokens=500)
    response = processor.decode(output[0], skip_special_tokens=True)

    # सहायक की प्रतिक्रिया निकालें
    return response.split("[/INST]")[-1].strip()

demo = gr.Interface(
    fn=analyze_image,
    inputs=[
        gr.Image(type="pil", label="छवि"),
        gr.Textbox(label="प्रश्न", value="इस छवि का विस्तार से वर्णन करें")
    ],
    outputs=gr.Textbox(label="प्रतिक्रिया"),
    title="LLaVA विज़न सहायक"
)

demo.launch(server_name="0.0.0.0", server_port=8000)
```

## एपीआई सर्वर

```python
from fastapi import FastAPI, UploadFile, File, Form
from transformers import LlavaNextProcessor, LlavaNextForConditionalGeneration
import torch
from PIL import Image
import io

app = FastAPI()

processor = LlavaNextProcessor.from_pretrained("llava-hf/llava-v1.6-mistral-7b-hf")
model = LlavaNextForConditionalGeneration.from_pretrained(
    "llava-hf/llava-v1.6-mistral-7b-hf",
    torch_dtype=torch.float16,
    device_map="auto"
)

@app.post("/analyze")
async def analyze(
    image: UploadFile = File(...),
    question: str = Form(default="इस छवि का वर्णन करें")
):
    img = Image.open(io.BytesIO(await image.read()))

    conversation = [
        {
            "role": "user",
            "content": [
                {"type": "image"},
                {"type": "text", "text": question}
            ]
        }
    ]

    prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
    inputs = processor(prompt, img, return_tensors="pt").to("cuda")

    output = model.generate(**inputs, max_new_tokens=500)
    response = processor.decode(output[0], skip_special_tokens=True)

    return {"response": response.split("[/INST]")[-1].strip()}

# चलाएँ: uvicorn server:app --host 0.0.0.0 --port 8000
```

## बैच प्रोसेसिंग

```python
from transformers import LlavaNextProcessor, LlavaNextForConditionalGeneration
import torch
from PIL import Image
import os

processor = LlavaNextProcessor.from_pretrained("llava-hf/llava-v1.6-mistral-7b-hf")
model = LlavaNextForConditionalGeneration.from_pretrained(
    "llava-hf/llava-v1.6-mistral-7b-hf",
    torch_dtype=torch.float16,
    device_map="auto"
)

def analyze_image(image_path, question):
    image = Image.open(image_path)

    conversation = [
        {"role": "user", "content": [
            {"type": "image"},
            {"type": "text", "text": question}
        ]}
    ]

    prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
    inputs = processor(prompt, image, return_tensors="pt").to("cuda")

    output = model.generate(**inputs, max_new_tokens=300)
    return processor.decode(output[0], skip_special_tokens=True).split("[/INST]")[-1].strip()

# छवियों के फ़ोल्डर को संसाधित करें
image_folder = "./images"
results = []

for filename in os.listdir(image_folder):
    if filename.endswith(('.jpg', '.png', '.jpeg')):
        path = os.path.join(image_folder, filename)
        description = analyze_image(path, "इस छवि का संक्षेप में वर्णन करें")
        results.append({"file": filename, "description": description})
        print(f"{filename}: {description[:100]}...")

# परिणाम सहेजें
import json
with open("descriptions.json", "w") as f:
    json.dump(results, f, indent=2)
```

## मेमोरी अनुकूलन

### 4-बिट क्वांटाइज़ेशन

```python
from transformers import BitsAndBytesConfig

quantization_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_compute_dtype=torch.float16
)

model = LlavaNextForConditionalGeneration.from_pretrained(
    "llava-hf/llava-v1.6-mistral-7b-hf",
    quantization_config=quantization_config,
    device_map="auto"
)
```

### CPU ऑफ़लोड

```python
model = LlavaNextForConditionalGeneration.from_pretrained(
    "llava-hf/llava-v1.6-mistral-7b-hf",
    torch_dtype=torch.float16,
    device_map="auto",
    offload_folder="offload"
)
```

## प्रदर्शन

| मॉडल          | GPU      | टोकन/सेकंड |
| ------------- | -------- | ---------- |
| LLaVA-1.5-7B  | RTX 3090 | \~30       |
| LLaVA-1.5-7B  | RTX 4090 | \~45       |
| LLaVA-1.6-7B  | RTX 4090 | \~40       |
| LLaVA-1.5-13B | A100     | \~35       |

## समस्या निवारण

### मेमोरी समाप्त

```python

# 4-बिट क्वांटाइज़ेशन का उपयोग करें

# या छोटा मॉडल उपयोग करें (13B के बजाय 7B)

# या छोटी छवियों को संसाधित करें
image = image.resize((336, 336))
```

### धीमी जनरेशन

* फ्लैश अटेंशन का उपयोग करें
* max\_new\_tokens कम करें
* क्वांटाइज़्ड मॉडल का उपयोग करें

### खराब गुणवत्ता

* बड़ा मॉडल उपयोग करें
* संदर्भ के साथ बेहतर प्रॉम्प्ट
* उच्च-रिज़ॉल्यूशन छवियाँ

## लागत का अनुमान

CLORE.AI मार्केटप्लेस की सामान्य दरें (2024 तक):

| GPU       | प्रति घंटा दर | प्रति दिन दर | 4-घंटे का सत्र |
| --------- | ------------- | ------------ | -------------- |
| RTX 3060  | \~$0.03       | \~$0.70      | \~$0.12        |
| RTX 3090  | \~$0.06       | \~$1.50      | \~$0.25        |
| RTX 4090  | \~$0.10       | \~$2.30      | \~$0.40        |
| A100 40GB | \~$0.17       | \~$4.00      | \~$0.70        |
| A100 80GB | \~$0.25       | \~$6.00      | \~$1.00        |

*मूल्य प्रदाता और मांग के अनुसार बदलते हैं। देखें* [*CLORE.AI मार्केटप्लेस*](https://clore.ai/marketplace) *वर्तमान दरों के लिए।*

**पैसे बचाएँ:**

* का उपयोग करें **स्पॉट** बाधित किए जा सकने वाले कार्य के लिए मार्केट — लगभग एक-तिहाई सर्वरों की स्पॉट कीमत ऑन-डिमांड से कम होती है (मध्य \~13% छूट), बाकी उससे मेल खाते हैं
* से भुगतान करें **CLORE** टोकन
* विभिन्न प्रदाताओं के बीच कीमतों की तुलना करें

## अगले चरण

* Ollama LLMs - Ollama के साथ LLaVA चलाएँ
* RAG + LangChain - विज़न + RAG
* vLLM इंफ़ेरेंस - प्रोडक्शन सर्विंग


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-hi/vision-models/llava-vision-language.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
