run.py 752 B

1234567891011121314151617181920212223242526272829
  1. import inspect
  2. import webbrowser
  3. from typing import Optional
  4. import uvicorn
  5. from . import globals
  6. def run(*,
  7. host: str = '0.0.0.0',
  8. port: int = 5000,
  9. title: str = 'NiceGUI',
  10. dark: Optional[bool] = False,
  11. reload: bool = True,
  12. binding_refresh_interval: float = 0.1,
  13. ) -> None:
  14. globals.host = host
  15. globals.port = port
  16. globals.title = title
  17. globals.dark = dark
  18. globals.binding_refresh_interval = binding_refresh_interval
  19. if inspect.stack()[-2].filename.endswith('spawn.py'):
  20. return
  21. webbrowser.open(f'http://{host if host != "0.0.0.0" else "127.0.0.1"}:{port}/')
  22. uvicorn.run('nicegui:app' if reload else globals.app, host=host, port=port, reload=reload)