From 0cfc0b016e4081e3bdc304d589c0c74d6606324b Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 8 Jun 2023 12:25:00 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20feat(=5F=5Fmain=5F=5F.py):=20add?= =?UTF-8?q?=20optional=20path=20argument=20to=20serve=20function=20to=20sp?= =?UTF-8?q?ecify=20path=20to=20frontend=20directory=20=F0=9F=9A=80=20feat(?= =?UTF-8?q?=5F=5Fmain=5F=5F.py):=20add=20optional=20open=5Fbrowser=20argum?= =?UTF-8?q?ent=20to=20serve=20function=20to=20specify=20whether=20to=20ope?= =?UTF-8?q?n=20browser=20after=20starting=20server=20The=20serve=20functio?= =?UTF-8?q?n=20now=20accepts=20an=20optional=20path=20argument=20to=20spec?= =?UTF-8?q?ify=20the=20path=20to=20the=20frontend=20directory=20containing?= =?UTF-8?q?=20build=20files.=20This=20is=20useful=20for=20development=20pu?= =?UTF-8?q?rposes=20only.=20The=20function=20also=20accepts=20an=20optiona?= =?UTF-8?q?l=20open=5Fbrowser=20argument=20to=20specify=20whether=20to=20o?= =?UTF-8?q?pen=20the=20browser=20after=20starting=20the=20server.=20This?= =?UTF-8?q?=20is=20useful=20when=20running=20the=20server=20locally.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/__main__.py | 34 ++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/backend/langflow/__main__.py b/src/backend/langflow/__main__.py index 8b3e9f773..8c9281862 100644 --- a/src/backend/langflow/__main__.py +++ b/src/backend/langflow/__main__.py @@ -89,6 +89,13 @@ def serve( log_file: Path = typer.Option("logs/langflow.log", help="Path to the log file."), jcloud: bool = typer.Option(False, help="Deploy on Jina AI Cloud"), dev: bool = typer.Option(False, help="Run in development mode (may contain bugs)"), + path: str = typer.Option( + None, + help="Path to the frontend directory containing build files. This is for development purposes only.", + ), + open_browser: bool = typer.Option( + True, help="Open the browser after starting the server." + ), ): """ Run the Langflow server. @@ -101,8 +108,11 @@ def serve( update_settings(config, dev=dev) app = create_app() # get the directory of the current file - path = Path(__file__).parent - static_files_dir = path / "frontend" + if not path: + path = Path(__file__).parent + static_files_dir = path / "frontend" + else: + static_files_dir = Path(path) app.mount( "/", StaticFiles(directory=static_files_dir, html=True), @@ -127,22 +137,30 @@ def serve( time.sleep(1) print_banner(host, port) - webbrowser.open(f"http://{host}:{port}") + if open_browser: + webbrowser.open(f"http://{host}:{port}") def print_banner(host, port): # console = Console() + word = "LangFlow" + colors = ["#690080", "#660099", "#4d00b3", "#3300cc", "#1a00e6", "#0000ff"] + + styled_word = "" + + for i, char in enumerate(word): + color = colors[i % len(colors)] + styled_word += f"[{color}]{char}[/]" + # Title with emojis and gradient text title = ( - "[bold yellow]:chains: Welcome to Langflow :chains:[/bold yellow]\n\n" + f"[bold]Welcome to :chains: {styled_word} [/bold]\n\n" f"Access [link=http://{host}:{port}]http://{host}:{port}[/link]" ) - - # Info with gradient text info_text = ( - "Access, collaborate, contribute, and explore at our " - "[bold magenta][link=https://github.com/logspace-ai/langflow]GitHub Repo[/link][/bold magenta] :rocket:" + "Collaborate, and contribute at our " + "[bold][link=https://github.com/logspace-ai/langflow]GitHub Repo[/link][/bold] :rocket:" ) # Create a panel with the title and the info text, and a border around it