Fix the chat box being off-screen, the scroll traps, and a sanitiser bug eating hyphens

#1
by ya02 - opened

Hi — these are fixes on top of your LangChain/RAG work (9c653b9), found while
reviewing this Space. Nothing of yours is reverted: langchain_llm.py, the
semantic search and the prompt changes all stay as you wrote them.

One bug is live right now. In engine._CJK_RE, the private-use-area range
'\ue000-\uf8ff' was flattened to a bare '-' somewhere in the web editor. The
class no longer strips PUA characters, and it does strip a literal ASCII
hyphen from every model reply — "التسجيل المباشر - المفاضلة" comes back
without its dash. Restored.

build_llm would break the Streamlit build. It imports llm.langchain_llm
unconditionally, but requirements-deploy.txt does not carry LangChain, so
every chat answer there would silently drop to the deterministic fallback.
LangChain is added to that manifest, and an ImportError now falls back to the
provider SDKs — the behaviour requirements.txt already describes in its own
comment ("cloud_llm.py is kept only as a documented fallback").

Four tests were patching a dead path. test_build_llm_* still monkeypatched
llm.cloud_llm.CloudLLM, which build_llm no longer calls. They patch the
LangChain path now; the contract under test is unchanged, since
langchain_llm.PROVIDER_PRECEDENCE is the same list. 148 tests pass with
LangChain installed and without it.

The chat box was unreachable. It is the last child of #kalim-main, so
position: sticky; bottom: 3rem had no room to lift it — measured, it sat
748px below the fold on a 1440x900 desktop and 873px below on a 390px phone. A
student saw ten result cards and no way to ask anything. It is fixed now,
tracking the main column. The footer also wraps to two lines at 390px (54px),
while the offsets guarding it were a flat 3rem and, on phones, 1.2rem — less
than the thing they were clearing. A small observer measures the footer, the
column and the composer into CSS variables instead of hardcoding them.

Two scroll traps. The conversation auto-scrolled to the bottom on any
mutation, so scrolling up to re-read something pulled you straight back down;
it now sticks only when you are already at the bottom, and a question you typed
re-sticks it. And the pane carried overscroll-behavior: contain while being
sized against the whole window, so on anything shorter than 900px the first
wizard question sat below the fold with no way to scroll to it — the pointer
was over a pane that would not chain its scroll.

The shortlist reads in order. It was a gr.render panel pinned below the
chat, so an answer to a question asked after the list appeared above the
list. Each batch is posted as a chat message of <details> cards now, so
"show more" appends underneath and so does every later answer. Opening a card
is still a client-side toggle. This needs the chatbot to render HTML, so
escaping moved into _bot/_user — model replies are escaped, only markup the
file writes is live.

Startup. The semantic index was built at import, before gr.Blocks was
defined, so the Space served nothing at all until the sentence-transformers
model had downloaded and all 95 majors were embedded — on every ZeroGPU
restart. It builds on a background thread now; the chat works without it.

CLAUDE.md records the layout constraints, so the next editing session does
not undo the measured offsets by replacing them with rem values again.

Happy to split this into smaller PRs if you would rather take it in pieces.

GhadaSaylami changed pull request status to merged

Superseded by #2, which adds a fix for the ZeroGPU CUDA error in the index build. Hugging Face only lets the repo owner push into an existing PR ref, so I could not add it here. Closing this one — please review #2 instead.

Correction to my previous comment — I wrote it before seeing that you had already merged this. #2 does not replace this PR; it adds one further fix on top of it (the ZeroGPU CUDA error in the index build). Sorry for the noise.

Sign up or log in to comment