🐛 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:
parent
9823b4c9c5
commit
72afbb834c
3 changed files with 73 additions and 16 deletions
|
|
@ -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,17 +115,66 @@ def serve(
|
||||||
"timeout": timeout,
|
"timeout": timeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
if platform.system() in ["Darwin", "Windows"]:
|
webapp_process = Process(
|
||||||
# Run using uvicorn on MacOS and Windows
|
target=run_langflow, args=(host, port, log_level, options, app)
|
||||||
# Windows doesn't support gunicorn
|
)
|
||||||
# MacOS requires an env variable to be set to use gunicorn
|
webapp_process.start()
|
||||||
import uvicorn
|
status_code = 0
|
||||||
|
while status_code != 200:
|
||||||
|
try:
|
||||||
|
status_code = httpx.get(f"http://{host}:{port}").status_code
|
||||||
|
except Exception:
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
uvicorn.run(app, host=host, port=port, log_level=log_level)
|
print_banner(host, port)
|
||||||
else:
|
webbrowser.open(f"http://{host}:{port}")
|
||||||
from langflow.server import LangflowApplication
|
|
||||||
|
|
||||||
LangflowApplication(app, options).run()
|
|
||||||
|
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"]:
|
||||||
|
# Run using uvicorn on MacOS and Windows
|
||||||
|
# Windows doesn't support gunicorn
|
||||||
|
# MacOS requires an env variable to be set to use gunicorn
|
||||||
|
import uvicorn
|
||||||
|
|
||||||
|
uvicorn.run(app, host=host, port=port, log_level=log_level)
|
||||||
|
else:
|
||||||
|
from langflow.server import LangflowApplication
|
||||||
|
|
||||||
|
LangflowApplication(app, options).run()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(e)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue