{
"event": "PreToolUse",
"tool_name": "Read",
"tool_input": {
"file_path": "\/var\/www\/scripts\/pipeline\/vision.py",
"limit": 100
}
}
{
"tool_response": {
"type": "text",
"file": {
"filePath": "\/var\/www\/scripts\/pipeline\/vision.py",
"content": "#!\/usr\/bin\/env python3\n\"\"\"\nVision analysis module for KI-System Pipeline.\nExtracts PDF pages as images and analyzes them with vision models.\n\nUsage:\n python vision.py <pdf_path> # Analyze all pages\n python vision.py <pdf_path> --page 1 # Analyze specific page\n\"\"\"\n\nimport base64\nimport os\nimport sys\nfrom pathlib import Path\n\nimport requests\n\nfrom config import OLLAMA_HOST\nfrom db import db\n\n# Default vision model (can be overridden by pipeline config)\nDEFAULT_VISION_MODEL = \"llama3.2-vision:11b\"\n\n# Image settings\nIMAGE_DPI = 150 # Balance between quality and size\nIMAGE_FORMAT = \"png\"\nMAX_IMAGE_SIZE_MB = 10\n\n\ndef pdf_to_images(file_path, dpi=IMAGE_DPI):\n \"\"\"\n Convert PDF pages to images.\n\n Args:\n file_path: Path to PDF file\n dpi: Resolution for image extraction\n\n Returns:\n List of dicts with page_number, image_bytes, width, height\n \"\"\"\n import fitz # PyMuPDF\n\n doc = fitz.open(file_path)\n pages = []\n\n for page_num in range(len(doc)):\n page = doc[page_num]\n\n # Render page to image\n mat = fitz.Matrix(dpi \/ 72, dpi \/ 72) # 72 is default PDF DPI\n pix = page.get_pixmap(matrix=mat)\n\n # Convert to PNG bytes\n img_bytes = pix.tobytes(IMAGE_FORMAT)\n\n pages.append(\n {\n \"page_number\": page_num + 1,\n \"image_bytes\": img_bytes,\n \"width\": pix.width,\n \"height\": pix.height,\n \"size_kb\": len(img_bytes) \/ 1024,\n }\n )\n\n doc.close()\n return pages\n\n\ndef analyze_image_ollama(image_bytes, model=DEFAULT_VISION_MODEL, prompt=None):\n \"\"\"\n Analyze an image using Ollama vision model.\n\n Args:\n image_bytes: PNG\/JPEG image as bytes\n model: Vision model name (e.g., minicpm-v:latest)\n prompt: Custom prompt (default: document analysis prompt)\n\n Returns:\n dict with analysis results\n \"\"\"\n if prompt is None:\n prompt = \"\"\"Analysiere diese Seite aus einem Schulungsdokument.\n\nBeschreibe strukturiert:\n1. **Überschriften\/Titel**: Welche Überschriften gibt es?\n2. **Hauptinhalt**: Worum geht es auf dieser Seite?\n3. **Visuelle Elemente**:\n - Gibt es Bilder\/Fotos? Was zeigen sie?\n - Gibt es Diagramme\/Charts? Was stellen sie dar?\n - Gibt es Tabellen? Was enthalten sie?\n4. **Layout**: Wie ist die Seite aufgebaut (Spalten, Boxen, etc.)?\n5. **Besonderheiten**: Gibt es Hervorhebungen, Zitate oder Callouts?\n\nAntworte auf Deutsch und sei präzise.\"\"\"\n\n # Encode image as base64\n image_base64 = base64.b64encode(image_bytes).decode(\"utf-8\")\n\n try:",
"numLines": 100,
"startLine": 1,
"totalLines": 389
}
}
}