therenald/humanitarianRAG
RQ1b user-study app (hosted)
Self-contained deploy copy of the counterbalanced user study. The original project is untouched; this directory is what gets pushed to a Hugging Face Space.
- App flow: access gate → welcome → (brief → timed work → Likert) ×4 → qualitative → done
- Tools compared: RAG (evidence synthesis, prompt B, hybrid retrieval) vs keyword (BM25)
- Source links: both tools show "Open PDF · p.N" + "Report page" links to the original ReliefWeb documents (uses
corpus_bundleA/corpus_metadata.csv, a slim doc_id→url map bundled here). RAG also has interactive inline citation pills. - Counterbalancing & tasks:
ui/study_config.py(identical to the local version) - Embedding model:
BAAI/bge-large-en-v1.5(downloads from the HF hub on first run) - Data: appended to a Google Sheet (
ui/sheets.py); falls back to local CSV if Sheets isn't configured
The host filesystem is ephemeral — responses MUST go to the Google Sheet, not local CSV, or they are lost on restart.
One-time setup
1. Google Sheet + service account (data sink)
- In Google Cloud Console → create a project → enable the Google Sheets API.
- Create a service account → add a JSON key → download it.
- Create a Google Sheet for the results. Copy its ID from the URL (
https://docs.google.com/spreadsheets/d/<THIS_IS_THE_ID>/edit). - Share the Sheet with the service account's email (
...@...iam.gserviceaccount.com) as Editor. (The app auto-createstask_dataandqualitativetabs.)
2. Create the Space
- huggingface.co → New Space → Docker SDK (blank) → CPU basic (free, 16 GB). (HF removed the native Streamlit SDK; the bundled
Dockerfileruns Streamlit on port 7860.) Or via CLI:hf repo create <name> --repo-type space --space_sdk docker. - Push this directory to the Space (see "Deploy" below).
3. Space secrets (Settings → Variables and secrets → add as Secrets)
On HF these become environment variables; ui/sheets.py reads GCP_SERVICE_ACCOUNT / SPREADSHEET_ID, and ui/study_app.py reads STUDY_PASSCODES, from the env. Give each participant only their own code in their invitation. (If STUDY_PASSCODES is unset, e.g. local dev, the gate is skipped and the welcome screen offers a participant dropdown instead.)
Deploy
cd study_deploy
git init && git lfs install
git lfs track "*.pkl" "*.sqlite3" "*.bin" # already in .gitattributes
git add . && git commit -m "Deploy user-study app"
git remote add origin https://huggingface.co/spaces/<user>/<space-name>
git push origin mainThe Space builds from requirements.txt and launches ui/study_app.py. First boot is slow (it downloads the ~1.3 GB bge-large model); subsequent boots are fast.
Local smoke test
Without secrets, the gate is skipped and writes fall back to local CSV:
streamlit run ui/study_app.pyUpdating tasks/wording later
ui/study_config.py here is a copy. If you change tasks/Likert wording in the main project, re-copy that file here before redeploying so the two stay in sync.
