🐛 fix(__main__.py): fix typo in sendAll function URL

✨ feat(__main__.py): add banner with title and info text to be displayed on server start
🐛 fix(App.tsx): fix API endpoint URL
The sendAll function URL had an extra forward slash. The API endpoint URL in App.tsx was incorrect and has been fixed. A banner with a title and info text has been added to be displayed on server start to provide users with more information about the application.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-06 23:29:42 -03:00
commit 72afbb834c
3 changed files with 73 additions and 16 deletions

View file

@ -1,20 +1,28 @@
import multiprocessing import sys
import time
import httpx
from multiprocess import Process, cpu_count
import platform import platform
from pathlib import Path from pathlib import Path
from rich.panel import Panel
from rich import box
from rich import print as rprint
import typer import typer
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
from langflow.main import create_app from langflow.main import create_app
from langflow.settings import settings from langflow.settings import settings
from langflow.utils.logger import configure from langflow.utils.logger import configure, logger
import webbrowser
app = typer.Typer() app = typer.Typer()
def get_number_of_workers(workers=None): def get_number_of_workers(workers=None):
if workers == -1: if workers == -1:
workers = (multiprocessing.cpu_count() * 2) + 1 workers = (cpu_count() * 2) + 1
return workers return workers
@ -77,7 +85,7 @@ def serve(
timeout: int = typer.Option(60, help="Worker timeout in seconds."), timeout: int = typer.Option(60, help="Worker timeout in seconds."),
port: int = typer.Option(7860, help="Port to listen on."), port: int = typer.Option(7860, help="Port to listen on."),
config: str = typer.Option("config.yaml", help="Path to the configuration file."), config: str = typer.Option("config.yaml", help="Path to the configuration file."),
log_level: str = typer.Option("info", help="Logging level."), log_level: str = typer.Option("critical", help="Logging level."),
log_file: Path = typer.Option("logs/langflow.log", help="Path to the log file."), 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"), jcloud: bool = typer.Option(False, help="Deploy on Jina AI Cloud"),
dev: bool = typer.Option(False, help="Run in development mode (may contain bugs)"), dev: bool = typer.Option(False, help="Run in development mode (may contain bugs)"),
@ -107,6 +115,50 @@ def serve(
"timeout": timeout, "timeout": timeout,
} }
webapp_process = Process(
target=run_langflow, args=(host, port, log_level, options, app)
)
webapp_process.start()
status_code = 0
while status_code != 200:
try:
status_code = httpx.get(f"http://{host}:{port}").status_code
except Exception:
time.sleep(1)
print_banner(host, port)
webbrowser.open(f"http://{host}:{port}")
def print_banner(host, port):
# console = Console()
# Title with emojis and gradient text
title = (
"[bold yellow]:chains: Welcome to Langflow :chains:[/bold yellow]\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:"
)
# Create a panel with the title and the info text, and a border around it
panel = Panel(
f"{title}\n{info_text}", box=box.ROUNDED, border_style="blue", expand=False
)
# Print the banner with a separator line before and after
rprint(panel)
def run_langflow(host, port, log_level, options, app):
"""
Run Langflow server on localhost
"""
try:
if platform.system() in ["Darwin", "Windows"]: if platform.system() in ["Darwin", "Windows"]:
# Run using uvicorn on MacOS and Windows # Run using uvicorn on MacOS and Windows
# Windows doesn't support gunicorn # Windows doesn't support gunicorn
@ -118,6 +170,11 @@ def serve(
from langflow.server import LangflowApplication from langflow.server import LangflowApplication
LangflowApplication(app, options).run() LangflowApplication(app, options).run()
except KeyboardInterrupt:
pass
except Exception as e:
logger.error(e)
sys.exit(1)
def main(): def main():

View file

@ -49,7 +49,7 @@ export default function App() {
// Initialize state variable for the version // Initialize state variable for the version
const [version, setVersion] = useState(""); const [version, setVersion] = useState("");
useEffect(() => { useEffect(() => {
fetch("/version") fetch("api/v1/version")
.then((res) => res.json()) .then((res) => res.json())
.then((data) => { .then((data) => {
setVersion(data.version); setVersion(data.version);

View file

@ -4,11 +4,11 @@ import axios, { AxiosResponse } from "axios";
import { FlowType } from "../../types/flow"; import { FlowType } from "../../types/flow";
export async function getAll(): Promise<AxiosResponse<APIObjectType>> { export async function getAll(): Promise<AxiosResponse<APIObjectType>> {
return await axios.get(`/all`); return await axios.get(`api/v1/all`);
} }
export async function sendAll(data: sendAllProps) { export async function sendAll(data: sendAllProps) {
return await axios.post(`/predict`, data); return await axios.post(`api/v1//predict`, data);
} }
export async function checkCode( export async function checkCode(