Files
Benjamin Boenisch 5a31f52310 Initial commit: breakpilot-lehrer - Lehrer KI Platform
Services: Admin-Lehrer, Backend-Lehrer, Studio v2, Website,
Klausur-Service, School-Service, Voice-Service, Geo-Service,
BreakPilot Drive, Agent-Core

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 23:47:26 +01:00

84 lines
1.9 KiB
Python

"""
AI Processor - Utility Functions
Image encoding and helper functions.
"""
from pathlib import Path
import base64
import shutil
import logging
from .config import BEREINIGT_DIR
logger = logging.getLogger(__name__)
def encode_image_to_data_url(input_path: Path) -> str:
"""
Encode an image file to a data URL for API requests.
Args:
input_path: Path to the image file
Returns:
Data URL string (data:image/jpeg;base64,...)
"""
image_bytes = input_path.read_bytes()
image_b64 = base64.b64encode(image_bytes).decode("utf-8")
return f"data:image/jpeg;base64,{image_b64}"
def encode_image_to_base64(input_path: Path) -> str:
"""
Encode an image file to base64 string.
Args:
input_path: Path to the image file
Returns:
Base64 encoded string
"""
image_bytes = input_path.read_bytes()
return base64.b64encode(image_bytes).decode("utf-8")
def dummy_process_scan(input_path: Path) -> Path:
"""
Simple copy to Bereinigt folder - kept as fallback.
Args:
input_path: Path to input file
Returns:
Path to copied file
"""
if not input_path.exists():
raise FileNotFoundError(f"Eingabedatei nicht gefunden: {input_path}")
new_name = input_path.stem + "_bereinigt" + input_path.suffix
target = BEREINIGT_DIR / new_name
shutil.copy2(input_path, target)
return target
def get_media_type(input_path: Path) -> str:
"""
Determine media type from file extension.
Args:
input_path: Path to the file
Returns:
MIME type string
"""
suffix = input_path.suffix.lower()
media_types = {
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".png": "image/png",
".gif": "image/gif",
".webp": "image/webp",
".pdf": "application/pdf",
}
return media_types.get(suffix, "image/jpeg")