Skip to content

Instantly share code, notes, and snippets.

@Proteusiq
Created December 5, 2025 14:36
Show Gist options
  • Select an option

  • Save Proteusiq/38a9e2eec873441c11e6def63b019463 to your computer and use it in GitHub Desktop.

Select an option

Save Proteusiq/38a9e2eec873441c11e6def63b019463 to your computer and use it in GitHub Desktop.
give bytes eyes
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "httpx",
# "rich",
# ]
# ///
# script require llama.cpp: > llama-server -hf ggml-org/SmolVLM-500M-Instruct-GGUF --n-predict -1
import base64
from pathlib import Path
from httpx import Client
def image_to_base64(path: Path) -> str:
data = base64.b64encode(path.read_bytes()).decode("utf-8")
return f"data:image/jpeg;base64,{data}"
def describe_image(image: Path) -> dict:
image_b64 = image_to_base64(image)
base_url = "http://localhost:8080"
payload = {
"model": "SmolVLM", # not used
"messages": [
{"role": "system", "content": "Describe what you see in 5 sentences"},
{
"role": "user",
"content": [{"type": "image_url", "image_url": {"url": image_b64}}],
},
],
"temperature": 0.0,
}
with Client(
base_url=base_url,
headers={"Content-Type": "application/json"},
timeout=None,
) as requests:
response = requests.post("/v1/chat/completions", json=payload)
return response.json()
if __name__ == "__main__":
from rich.console import Console
from rich.markdown import Markdown
beer = Path("beer.png")
results = describe_image(beer)
text = results["choices"][0]["message"]["content"]
console = Console()
console.print(Markdown(text))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment