mirror of
https://github.com/open-webui/computer.git
synced 2026-11-23 14:10:45 -05:00
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
import click
|
|
import uvicorn
|
|
|
|
|
|
@click.group()
|
|
def cli():
|
|
"""cptr - your computer, from anywhere."""
|
|
pass
|
|
|
|
|
|
@cli.command()
|
|
@click.option("--host", default="0.0.0.0", help="Host to bind to.")
|
|
@click.option("--port", default=8000, type=int, help="Port to bind to.")
|
|
@click.option("--reload", is_flag=True, default=False, help="Enable auto-reload.")
|
|
@click.option("--headless", is_flag=True, default=False, help="Don't open browser.")
|
|
def run(host: str, port: int, reload: bool, headless: bool):
|
|
"""Start the cptr server."""
|
|
import os, secrets
|
|
display_host = 'localhost' if host == '0.0.0.0' else host
|
|
|
|
token = secrets.token_hex(32)
|
|
os.environ["CPTR_STARTUP_TOKEN"] = token
|
|
url = f"http://{display_host}:{port}/?token={token}"
|
|
|
|
print(f"\n ➜ {url}\n")
|
|
if not headless:
|
|
import threading, webbrowser
|
|
threading.Timer(1.5, lambda: webbrowser.open(url)).start()
|
|
uvicorn.run(
|
|
"cptr.app:application",
|
|
host=host,
|
|
port=port,
|
|
reload=reload,
|
|
)
|
|
|
|
|
|
def main():
|
|
cli()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|