caelum0x 174222bcaa feat: Builder-Track named-user tools, bio + evidence-intelligence platform, Apache-2.0
Builds PaperTrail from the base skeleton into a full evidence-verification platform
for the "Built with Claude: Life Sciences" hackathon (Builder Track).

New named-user features (Build Beyond the Bench):
- Lab Notebook Companion — rough bench notes -> structured, searchable, grounded
  experiment records (lib/labNotebook, /console/lab-notebook, migration 0059)
- Clinical Trial Matcher — de-identified patient notes -> ranked eligible
  ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning
  (lib/trialMatcher, /console/trial-matcher, migrations 0060)

Platform:
- Deterministic verification moat (biostats recompute, exact-span grounding)
- 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar,
  PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier)
- Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise
  governance (RBAC, /api/v1 gateway, metering, audit chain, retention)
- 17 OSS projects assimilated into native TypeScript on our stack (backend/engines
  retained + credited in NOTICE)
- Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site
- Next.js 16 upgrade, benchmark harness (honest smoke-test caveat)

Licensing: Apache-2.0 (LICENSE + NOTICE).
2026-07-10 16:23:13 +03:00

93 lines
3.6 KiB
Python

import asyncio
import os
from typing import List, Union
from langchain_community.document_loaders import (
PyMuPDFLoader,
TextLoader,
UnstructuredCSVLoader,
UnstructuredExcelLoader,
UnstructuredMarkdownLoader,
UnstructuredPowerPointLoader,
UnstructuredWordDocumentLoader
)
from langchain_community.document_loaders import BSHTMLLoader
class DocumentLoader:
def __init__(self, path: Union[str, List[str]]):
self.path = path
async def load(self) -> list:
tasks = []
if isinstance(self.path, list):
for file_path in self.path:
if os.path.isfile(file_path): # Ensure it's a valid file
filename = os.path.basename(file_path)
file_name, file_extension_with_dot = os.path.splitext(filename)
file_extension = file_extension_with_dot.strip(".").lower()
tasks.append(self._load_document(file_path, file_extension))
elif isinstance(self.path, (str, bytes, os.PathLike)):
for root, dirs, files in os.walk(self.path):
for file in files:
file_path = os.path.join(root, file)
file_name, file_extension_with_dot = os.path.splitext(file)
file_extension = file_extension_with_dot.strip(".").lower()
tasks.append(self._load_document(file_path, file_extension))
else:
raise ValueError("Invalid type for path. Expected str, bytes, os.PathLike, or list thereof.")
# for root, dirs, files in os.walk(self.path):
# for file in files:
# file_path = os.path.join(root, file)
# file_name, file_extension_with_dot = os.path.splitext(file_path)
# file_extension = file_extension_with_dot.strip(".")
# tasks.append(self._load_document(file_path, file_extension))
docs = []
for pages in await asyncio.gather(*tasks):
for page in pages:
if page.page_content:
docs.append({
"raw_content": page.page_content,
"url": os.path.basename(page.metadata['source'])
})
if not docs:
raise ValueError("🤷 Failed to load any documents!")
return docs
async def _load_document(self, file_path: str, file_extension: str) -> list:
ret_data = []
try:
loader_dict = {
"pdf": PyMuPDFLoader(file_path),
"txt": TextLoader(file_path),
"doc": UnstructuredWordDocumentLoader(file_path),
"docx": UnstructuredWordDocumentLoader(file_path),
"pptx": UnstructuredPowerPointLoader(file_path),
"csv": UnstructuredCSVLoader(file_path, mode="elements"),
"xls": UnstructuredExcelLoader(file_path, mode="elements"),
"xlsx": UnstructuredExcelLoader(file_path, mode="elements"),
"md": UnstructuredMarkdownLoader(file_path),
"html": BSHTMLLoader(file_path),
"htm": BSHTMLLoader(file_path)
}
loader = loader_dict.get(file_extension, None)
if loader:
try:
ret_data = loader.load()
except Exception as e:
print(f"Failed to load HTML document : {file_path}")
print(e)
except Exception as e:
print(f"Failed to load document : {file_path}")
print(e)
return ret_data