Spaces:
Sleeping
Sleeping
Graceful startup — show setup guide if credentials missing
Browse files10 unmodified lines111213141516171415201617181920212223242526222324272829303132333435363738394041424344454647484950514 unmodified lines565758596061626322 unmodified lines868788899091929310 unmodified linessys.stdout.reconfigure(encoding="utf-8")
import gradio as gr
from openmark.agent.graph import build_agent, ask
from openmark.embeddings.factory import get_embedder
from openmark.stores import chroma as chroma_store
from openmark.stores import neo4j_store
from openmark import config
# Load once at startup
# Load once at startup — fail gracefully if credentials are not configured
print("Loading OpenMark...")
_embedder = None
_agent = None
_setup_error = None
try:
from openmark.embeddings.factory import get_embedder
from openmark.agent.graph import build_agent, ask
from openmark.stores import chroma as chroma_store
from openmark.stores import neo4j_store
_embedder = get_embedder()
_agent = build_agent()
print("OpenMark ready.")
_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_READY
if not query.strip():
return "Enter a search query."
22 unmodified lines# ── Stats tab ─────────────────────────────────────────────────
def stats_fn():
if _embedder is None:
return _NOT_READY
chroma = chroma_store.get_stats()
neo4j = neo4j_store.get_stats()
openmark/ui/app.py+31-8