Download app.py from localailb/assistant: direct link, hf CLI and curl.
- Browser
- Download file 2.75 kB
-
https://huggingface.co/spaces/localailb/assistant/resolve/main/app.py
- Command line
-
hf download hf://spaces/localailb/assistant/app.py
-
curl -L -o app.py https://huggingface.co/spaces/localailb/assistant/resolve/main/app.py
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") | |