Framework auto-detection
Sniffing the imports in pasted code to suggest the right pip install.
Code example
code = '''
import xgboost as xgb
from sklearn.metrics import accuracy_score
'''
# auto-detect
if 'xgboost' in code or 'import xgb' in code:
framework = 'xgboost'
elif 'lightgbm' in code:
framework = 'lightgbm'
else:
framework = 'sklearn'
How it works
When a user pastes code into /convert, the page greps the code for import statements to guess the framework. This drives the UI hint ('Detected: XGBoost — installing xgboost…') and decides which packages to install before running the cell. The same trick powers the notebook's package recommendation engine: parse the imports, check which ones aren't installed, suggest the pip install commands.
🔍 Where this is used in OpenBenchML
templates/convert.html — JS auto-detects the framework from the pasted code.