Spaces:
Sleeping
Sleeping
File size: 1,255 Bytes
7d05933 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | """
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
|