Aniket2003333333's picture
start
7248d39
Raw
History Blame Contribute Delete
2.36 kB
# state.py
"""Shared Gradio state helpers."""
from __future__ import annotations
from typing import List, Literal, Optional
SearchMode = Literal["all", "single"]
AppMode = Literal["qa", "summary", "ocr", "entities", "documents"]
MODE_LABELS: dict[AppMode, str] = {
"qa": "Finance QA Chatbot",
"summary": "Financial Summary",
"ocr": "Document OCR",
"entities": "Entity Extraction",
"documents": "Documents",
}
def default_search_mode() -> SearchMode:
return "all"
def default_app_mode() -> AppMode:
return "qa"
def default_selected_doc_ids() -> List[str]:
return []
def default_session_id() -> Optional[str]:
return None
def mode_label(search_mode: SearchMode) -> str:
return "Hybrid RAG" if search_mode == "all" else "Single Document"
def center_title(app_mode: AppMode, search_mode: SearchMode) -> str:
if app_mode == "qa":
return mode_label(search_mode)
return MODE_LABELS[app_mode]
def footer_hint(
search_mode: SearchMode,
selected_doc_ids: List[str],
doc_count: int | None = None,
app_mode: AppMode = "qa",
) -> str:
if app_mode == "documents":
indexed = doc_count if doc_count is not None else 0
return f"Drop a file above or click Upload & index · {indexed} doc(s) indexed"
if app_mode != "qa":
return "Tap + to switch features or upload documents"
base = "Enter sends · Shift+Enter newline"
mode_key = "hybrid" if search_mode == "all" else "single"
if search_mode == "single":
n = len(selected_doc_ids) if selected_doc_ids else 0
return f"{base} · Mode: {mode_key} · {n} doc(s) selected"
if selected_doc_ids:
return f"{base} · Mode: {mode_key} · {len(selected_doc_ids)} doc(s) scoped for RAG"
indexed = doc_count if doc_count is not None else 0
return f"{base} · Mode: {mode_key} · {indexed} doc(s) indexed"
DEFAULT_FOOTER = footer_hint("all", [], 0)
WELCOME_MESSAGE = (
"Hello! I'm **FinSight AI**. Upload a financial document and ask me anything about it — "
"earnings reports, balance sheets, risk disclosures, or OCR extraction."
)
EMPTY_STATE_HTML = """
<div class="fs-empty-state">
<div class="fs-empty-logo">FinSight AI</div>
<p class="fs-empty-sub">Upload financial documents and ask questions about revenue, balance sheets, and more.</p>
</div>
"""