""" 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")