feat: Add screenshot processing adapters
This commit is contained in:
23
utils.py
Normal file
23
utils.py
Normal 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
|
||||
Reference in New Issue
Block a user