File size: 2,754 Bytes
bc9f3e6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | """
LocalAiLab Assistant β by LocalAiLab
smolagents + ChromaDB + Dynamic Hardware Support + Svelte Web UI
=======================================================================
Tabs:
π¬ General Chat β direct LLM conversation, no retrieval
π RAG Chat β retrieves from ChromaDB before answering
π¬ Deep Research β iterative multi-agent web research
πΌοΈ Vision Chat β image upload, answers from the image only (no KB)
ποΈ Speech to Text β transcribe audio to text using Whisper
π Data Analysis β AI agent explores CSV/Excel, builds charts + report
π Knowledge Base β index / manage documents
βοΈ Settings β system & model configuration
βΉοΈ About β bilingual system info
"""
import os
import socket
import threading
import warnings
import webbrowser
from pathlib import Path
os.environ.setdefault("HF_HUB_DISABLE_TELEMETRY", "1")
os.environ.setdefault("DO_NOT_TRACK", "1")
# Force the non-GUI matplotlib backend app-wide (see run_webview.py β the
# tkinter splash must never collide with matplotlib's TkAgg auto-select in
# the Data worker thread; `Tcl_AsyncDelete` would abort the process).
os.environ.setdefault("MPLBACKEND", "Agg")
try:
from dotenv import load_dotenv
from backend.paths import user_data_dir
user_env = str(user_data_dir() / ".env")
if os.path.exists(user_env):
load_dotenv(user_env)
else:
load_dotenv()
except ImportError:
pass
from backend import web_api
APP_ICON = Path(__file__).parent / "ui" / "image" / "logo_round.png"
def _find_free_port(start=7861):
for port in range(start, start + 20):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
if s.connect_ex(("127.0.0.1", port)) != 0:
return port
return start
warnings.filterwarnings("ignore", category=UserWarning, module="torch")
if __name__ == "__main__":
import multiprocessing
multiprocessing.freeze_support()
# Shared Windows stdio hardening: replaces None OR broken-handle
# streams (a GUI-launched process can have a sys.stdout whose OS handle
# is invalid β print() then raises OSError [WinError 6] and kills the
# run) and forces UTF-8 + errors=replace on the rest.
from backend.stdio_hardening import harden_stdio, harden_subprocesses
from backend.metadata_hardening import harden_metadata
harden_stdio()
harden_subprocesses()
harden_metadata()
port = _find_free_port()
# Open browser on startup
threading.Timer(0.8, lambda: webbrowser.open(f"http://127.0.0.1:{port}")).start()
web_api.run(host="127.0.0.1", port=port, log_level="info")
|