Spaces:
Runtime error
Runtime error
| """ | |
| Central configuration module for the Oculus server. | |
| All environment variables and configuration settings are defined here. | |
| """ | |
| import os | |
| from typing import Dict, Any, Tuple | |
| # OCR Configuration | |
| OCR_BACKEND = os.getenv("OCR_BACKEND", "easyocr") # Options: "easyocr" or "google" | |
| OCR_NUM_WORKERS = int(os.getenv("OCR_NUM_WORKERS", "1")) | |
| OCR_CONFIDENCE_THRESHOLD = float(os.getenv("OCR_CONFIDENCE_THRESHOLD", "0.2")) | |
| GOOGLE_APPLICATION_CREDENTIALS = os.getenv("GOOGLE_APPLICATION_CREDENTIALS") | |
| # UI Element Detection Configuration | |
| UI_MODEL_PATH = os.getenv("UI_MODEL_PATH", "weights/best.pt") | |
| # Image Annotation Configuration | |
| ANNOTATION_DIR = os.getenv("ANNOTATION_DIR", "annotated") | |
| FONT_SIZE = int(os.getenv("FONT_SIZE", "30")) | |
| JPEG_QUALITY = int(os.getenv("JPEG_QUALITY", "85")) | |
| # Whether to display code labels/annotations for text (OCR) elements | |
| ANNOTATE_TEXT = os.getenv("ANNOTATE_TEXT", "1").lower() in ("1", "true", "yes", "on") | |
| # Whether to draw bounding boxes around text (OCR) elements | |
| DRAW_TEXT_BOXES = os.getenv("DRAW_TEXT_BOXES", "1").lower() in ("1", "true", "yes", "on") | |
| # Whether to draw arrows from code labels to their bounding boxes | |
| DRAW_ARROWS = os.getenv("DRAW_ARROWS", "1").lower() in ("1", "true", "yes", "on") | |
| # Arrow line width | |
| ARROW_WIDTH = int(os.getenv("ARROW_WIDTH", "2")) | |
| # Element code label border width | |
| LABEL_BORDER_WIDTH = int(os.getenv("LABEL_BORDER_WIDTH", "3")) | |
| # Server Configuration | |
| PORT = int(os.getenv("PORT", "8000")) | |
| WORKERS = int(os.getenv("WORKERS", "1")) | |
| # Hardware Acceleration Settings | |
| PYTORCH_ENABLE_MPS_FALLBACK = os.getenv("PYTORCH_ENABLE_MPS_FALLBACK", "1") | |
| # Ensure annotation directory exists | |
| os.makedirs(ANNOTATION_DIR, exist_ok=True) | |
| def get_all_config() -> Dict[str, Any]: | |
| """Return all configuration values as a dictionary.""" | |
| return { | |
| "OCR_BACKEND": OCR_BACKEND, | |
| "OCR_NUM_WORKERS": OCR_NUM_WORKERS, | |
| "OCR_CONFIDENCE_THRESHOLD": OCR_CONFIDENCE_THRESHOLD, | |
| "GOOGLE_APPLICATION_CREDENTIALS": GOOGLE_APPLICATION_CREDENTIALS, | |
| "UI_MODEL_PATH": UI_MODEL_PATH, | |
| "ANNOTATION_DIR": ANNOTATION_DIR, | |
| "FONT_SIZE": FONT_SIZE, | |
| "JPEG_QUALITY": JPEG_QUALITY, | |
| "ANNOTATE_TEXT": ANNOTATE_TEXT, | |
| "DRAW_TEXT_BOXES": DRAW_TEXT_BOXES, | |
| "DRAW_ARROWS": DRAW_ARROWS, | |
| "ARROW_WIDTH": ARROW_WIDTH, | |
| "LABEL_BORDER_WIDTH": LABEL_BORDER_WIDTH, | |
| "PORT": PORT, | |
| "WORKERS": WORKERS, | |
| "PYTORCH_ENABLE_MPS_FALLBACK": PYTORCH_ENABLE_MPS_FALLBACK | |
| } |