Sushruta / config.py
AnkTechsol
Initial commit with Git LFS
fb95f15
Raw
History Blame Contribute Delete
3.73 kB
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Unified configuration for Sushruta Patient 360."""
import csv
import logging
import os
from pathlib import Path
logger = logging.getLogger(__name__)
# ── Base paths ──────────────────────────────────────────────────────────────
BASE_DIR = Path(__file__).resolve().parent
# ── Environment variables ───────────────────────────────────────────────────
HF_TOKEN = os.environ.get("HF_TOKEN", "")
MEDGEMMA_27B_ENDPOINT = os.environ.get("MEDGEMMA_27B_ENDPOINT", "")
MEDGEMMA_4B_ENDPOINT = os.environ.get("MEDGEMMA_4B_ENDPOINT", "")
GENERATE_SPEECH = os.environ.get("GENERATE_SPEECH", "false").lower() in (
"true",
"1",
"yes",
)
CACHE_DIR = Path(os.environ.get("CACHE_DIR", "/cache"))
FRONTEND_BUILD = Path(
os.environ.get("FRONTEND_BUILD", str(BASE_DIR / "frontend" / "build"))
)
# ── Radiology report manifest ──────────────────────────────────────────────
AVAILABLE_REPORTS: dict[str, dict] = {}
def load_reports_manifest() -> dict[str, dict]:
"""Load the radiology reports manifest from static/reports_manifest.csv.
CSV columns: image_type, case_display_name, image_path, report_path
Returns a dict keyed by case_display_name.
"""
manifest_path = BASE_DIR / "static" / "reports_manifest.csv"
reports: dict[str, dict] = {}
if not manifest_path.exists():
logger.warning("Reports manifest not found at %s", manifest_path)
return reports
with open(manifest_path, newline="", encoding="utf-8") as f:
reader = csv.DictReader(f)
for row in reader:
image_type = row.get("image_type", "").strip()
case_name = row.get("case_display_name", "").strip()
image_path = row.get("image_path", "").strip()
report_path = row.get("report_path", "").strip()
if not case_name:
continue
# Validate file paths exist (relative to BASE_DIR)
abs_image = BASE_DIR / image_path
abs_report = BASE_DIR / report_path
if not abs_image.exists():
logger.warning(
"Image file not found for report '%s': %s",
case_name,
abs_image,
)
if not abs_report.exists():
logger.warning(
"Report file not found for report '%s': %s",
case_name,
abs_report,
)
reports[case_name] = {
"image_type": image_type,
"case_display_name": case_name,
"image_path": image_path,
"report_path": report_path,
}
logger.info("Loaded %d radiology reports from manifest", len(reports))
return reports
# Load manifest at import time
AVAILABLE_REPORTS = load_reports_manifest()