phi_inference / test_vision.py
Leon4gr45's picture
port verified llama.cpp CPU proxy: LFM2.5-VL-1.6B vision via mmproj, native OpenAI multimodal API, prebuilt binary
4baaa2f verified
Raw History Blame Contribute Delete
1.13 kB
"""Smoke test: text chat + vision (image_url) against the phi_inference Space."""
import base64
import json
import sys
import requests
BASE = "https://Leon4gr45-phi-inference.hf.space"
# 1) text-only
r = requests.post(f"{BASE}/v1/chat/completions", json={
"model": "lfm2.5-vl-1.6b",
"messages": [{"role": "user", "content": "Say hello in one sentence."}],
"max_tokens": 48,
}, timeout=180)
print("TEXT:", json.dumps(r.json(), indent=2)[:500])
# 2) vision — pass an image path as argv[1], else skip
if len(sys.argv) > 1:
with open(sys.argv[1], "rb") as f:
b64 = base64.b64encode(f.read()).decode()
r = requests.post(f"{BASE}/v1/chat/completions", json={
"model": "lfm2.5-vl-1.6b",
"messages": [{"role": "user", "content": [
{"type": "text", "text": "Describe this image in detail."},
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{b64}"}},
]}],
"max_tokens": 256,
}, timeout=300)
print("VISION:", r.json()["choices"][0]["message"]["content"])
else:
print("(pass an image path as argv[1] to test vision)")