SamyamLM-V1 / inference.py
techindro's picture
Upload inference.py
919e120 verified
Raw History Blame Contribute Delete
1.54 kB
#!/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)