File size: 1,542 Bytes
919e120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
SamyamLM-V1 — Test Inference Client
Quickly run spatial & satellite image analysis with local Ollama runtime.
"""

import sys
import base64
import requests

def analyze_image(image_path: str, prompt: str = "Analyze this image and identify all objects with bounding boxes."):
    # 1. Base64 encode the image
    with open(image_path, "rb") as f:
        img_b64 = base64.b64encode(f.read()).decode("utf-8")

    # 2. Query local SamyamLM server
    payload = {
        "model": "samyam-lm-v1",
        "prompt": prompt,
        "images": [img_b64],
        "stream": False,
        "options": {
            "temperature": 0.2,
            "top_p": 0.9
        }
    }

    try:
        response = requests.post("http://localhost:11434/api/generate", json=payload)
        response.raise_for_status()
        return response.json().get("response", "")
    except requests.exceptions.ConnectionError:
        return "❌ Error: Ollama is not running on http://localhost:11434. Start it with: ollama serve"

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: python inference.py <path_to_satellite_or_drone_image.jpg> [prompt]")
        sys.exit(1)

    img_path = sys.argv[1]
    user_prompt = sys.argv[2] if len(sys.argv) > 2 else "Describe tactical assets and provide bounding boxes [ymin, xmin, ymax, xmax]."
    
    print(f"🛰️ Running SamyamLM-V1 inference on: {img_path}...")
    result = analyze_image(img_path, user_prompt)
    print("\n--- Model Output ---")
    print(result)