feat: Add screenshot processing adapters

This commit is contained in:
2026-03-07 12:30:32 +05:30
parent 8715ebafe8
commit e6c3eec5bb
7 changed files with 1340 additions and 2 deletions

23
utils.py Normal file
View File

@@ -0,0 +1,23 @@
import base64
import json
from jsonschema import validate, ValidationError
def img2base64(image_path: str) -> str:
"""
Converts image to base64 encoded string
"""
with open(image_path, "rb") as f:
base64_encoded = base64.b64encode(f.read()).decode("utf-8")
return f"data:image/png;base64,{base64_encoded}"
def is_valid_json_schema(json_string: str, schema: dict) -> bool:
try:
data = json.loads(json_string)
validate(instance=data, schema=schema)
return True
except (json.JSONDecodeError, ValidationError):
return False