import requests
import base64
from PIL import Image

image_path = '/root/.hermes/cache/images/img_668b1b2125b9.jpg'

# 读取并放大图片
img = Image.open(image_path)
img_large = img.resize((img.width * 2, img.height * 2), Image.LANCZOS)
img_large.save('/tmp/img_2x.png')

with open('/tmp/img_2x.png', 'rb') as f:
    img_b64 = base64.b64encode(f.read()).decode()

# 用更精确的提示，聚焦在中文文字识别
resp = requests.post('http://localhost:11434/api/generate', json={
    'model': 'llava-phi3',
    'prompt': 'This is a Chinese mobile app UI comparison image. Read ALL Chinese text character by character. Focus on: 1) The two column headers on top. 2) Any text about "签约" or "转入". 3) Any text about "7天" or "通知存款" or "5万元". 4) All UI labels and button text. Output every Chinese character you can find.',
    'images': [img_b64],
    'stream': False,
    'options': {'num_predict': 3000, 'temperature': 0.1, 'num_ctx': 4096}
}, timeout=300)

result = resp.json()
print(result.get('response', ''))
