Spaces:
Paused

assistant / app.py
localailb's picture
Deploy Full LocalAiLab Application (FastAPI + Svelte + Agents)
bc9f3e6 verified
Raw History Blame Contribute Delete
2.75 kB
"""
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")