Spaces:
Sleeping
Sleeping
Graceful startup — show setup guide if credentials missing
Browse files10 unmodified lines111213141516171819202122232425262728293031324 unmodified lines37383940414222 unmodified lines65666768697010 unmodified linessys.stdout.reconfigure(encoding="utf-8")import gradio as grfrom openmark.agent.graph import build_agent, askfrom openmark.embeddings.factory import get_embedderfrom openmark.stores import chroma as chroma_storefrom openmark.stores import neo4j_storefrom openmark import config# Load once at startupprint("Loading OpenMark...")_embedder = get_embedder()_agent = build_agent()print("OpenMark ready.")# ── Chat tab ──────────────────────────────────────────────────def chat_fn(message: str, history: list, thread_id: str):if not message.strip():return history, ""response = ask(_agent, message, thread_id=thread_id or "default")4 unmodified lines# ── Search tab ────────────────────────────────────────────────def search_fn(query: str, category: str, min_score: float, n_results: int):if not query.strip():return "Enter a search query."22 unmodified lines# ── Stats tab ─────────────────────────────────────────────────def stats_fn():chroma = chroma_store.get_stats()neo4j = neo4j_store.get_stats()10 unmodified lines11121314151617181920212223242526272829303132333435363738394041424344454647484950514 unmodified lines565758596061626322 unmodified lines868788899091929310 unmodified linessys.stdout.reconfigure(encoding="utf-8")import gradio as grfrom openmark import config# Load once at startup — fail gracefully if credentials are not configuredprint("Loading OpenMark...")_embedder = None_agent = None_setup_error = Nonetry:from openmark.embeddings.factory import get_embedderfrom openmark.agent.graph import build_agent, askfrom openmark.stores import chroma as chroma_storefrom openmark.stores import neo4j_store_embedder = get_embedder()_agent = build_agent()print("OpenMark ready.")except Exception as e:_setup_error = str(e)print(f"OpenMark setup incomplete: {e}")# ── Chat tab ──────────────────────────────────────────────────_NOT_READY = ("## Setup required\n\n""This Space is a **demo shell** — it requires your own credentials to run.\n\n""See the [GitHub repo](https://github.com/OthmanAdi/OpenMark) for full setup instructions.\n\n"f"```\n{_setup_error}\n```" if _setup_error else "")def chat_fn(message: str, history: list, thread_id: str):if _agent is None:history.append((message, _NOT_READY))return history, ""if not message.strip():return history, ""response = ask(_agent, message, thread_id=thread_id or "default")4 unmodified lines# ── Search tab ────────────────────────────────────────────────def search_fn(query: str, category: str, min_score: float, n_results: int):if _embedder is None:return _NOT_READYif not query.strip():return "Enter a search query."22 unmodified lines# ── Stats tab ─────────────────────────────────────────────────def stats_fn():if _embedder is None:return _NOT_READYchroma = chroma_store.get_stats()neo4j = neo4j_store.get_stats()
openmark/ui/app.py+31-8