fulviodeo's picture
Refactoring
7d05933
raw
history blame
1.26 kB
"""
App-level utility functions for PopulationHealthScreener.
Import these at the top of the notebook before building any widgets.
"""
def silence_libraries():
"""
Suppress verbose output from ML libraries before model loading.
Call once at startup. Sets TRANSFORMERS_VERBOSITY=error,
TQDM_DISABLE=1, and raises the log level for transformers and torch
to ERROR so they stay quiet during inference.
"""
import warnings, os, logging
warnings.filterwarnings("ignore")
os.environ['TRANSFORMERS_VERBOSITY'] = 'error'
os.environ['TQDM_DISABLE'] = '1'
logging.getLogger("transformers").setLevel(logging.ERROR)
logging.getLogger("torch").setLevel(logging.ERROR)
def exec_script(path, inputs):
"""
Run a script from disk inside a fresh namespace.
Pass inputs as a dict — the script reads them via globals().get().
The script's local variables stay in the returned namespace;
nothing bleeds into the caller's scope.
ns = exec_script('src/search_pubmed.py', {'query_selector': qs, ...})
table = ns['articles_table']
"""
import os
ns = dict(inputs)
with open(os.path.abspath(os.path.join(os.getcwd(), path))) as f:
exec(f.read(), ns)
return ns