mirror of
https://github.com/open-webui/computer.git
synced 2026-11-07 21:56:05 +03:00
53 lines
1.2 KiB
Python
53 lines
1.2 KiB
Python
import click
|
|
import uvicorn
|
|
|
|
|
|
@click.group()
|
|
def cli():
|
|
"""Your computer, from anywhere."""
|
|
pass
|
|
|
|
|
|
@cli.command()
|
|
@click.option(
|
|
"--host",
|
|
default="127.0.0.1",
|
|
show_default=True,
|
|
help="Host to bind to. Use 0.0.0.0 to allow access from other devices.",
|
|
)
|
|
@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
|
|
import secrets
|
|
|
|
display_host = "localhost" if host == "0.0.0.0" else host
|
|
|
|
token = secrets.token_hex(32)
|
|
os.environ["CPTR_STARTUP_TOKEN"] = token
|
|
os.environ["CPTR_PORT"] = str(port)
|
|
url = f"http://{display_host}:{port}/?token={token}"
|
|
|
|
print(f"\n ➜ {url}\n")
|
|
if not headless:
|
|
import threading
|
|
import 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()
|