Decoder2704/python-chatbot-jay
0
1# Backend run steps2 3Paths below use your **project root** (`pybot_NLP/`, parent of `backend/`) or the **`backend/`** folder. Scripts resolve paths from their own location, but you should still run commands as shown so imports and subprocess steps behave as expected.4 5Install dependencies once (from project root or with `-r` path adjusted):6 7```bash8pip install -r backend/requirements.txt9```10 11Raw Stack Overflow CSVs should live in **`pybot_data/`** at the project root (`pybot_data/Answers.csv`, `pybot_data/Questions.csv`).12 13---14 15## From project root (`pybot_NLP/`)16 17### Build pipeline (order matters)18 19```bash20python backend/scripts/build_answers_v2.py21```22 23```bash24python backend/scripts/build_final_dataset.py25```26 27```bash28python backend/scripts/build_retrieval_artifacts.py29```30 31Or run all three in sequence:32 33```bash34python backend/scripts/run_all_build_steps.py35```36 37### Verify artifacts and data38 39```bash40python backend/debug/verify_project.py41```42 43Other checks (optional):44 45```bash46python backend/debug/check_files.py47```48 49```bash50python backend/debug/validate_dataset.py51```52 53### Run the FastAPI server54 55```bash56cd backend && uvicorn app.main:app --host 127.0.0.1 --port 800057```58 59From project root without changing directory:60 61```bash62cd backend && uvicorn app.main:app --host 127.0.0.1 --port 8000 && cd ..63```64 65Health check (in another terminal):66 67```bash68curl -s http://127.0.0.1:8000/health69```70 71---72 73## From inside `backend/`74 75### Build pipeline76 77```bash78python scripts/build_answers_v2.py79```80 81```bash82python scripts/build_final_dataset.py83```84 85```bash86python scripts/build_retrieval_artifacts.py87```88 89```bash90python scripts/run_all_build_steps.py91```92 93### Verify94 95```bash96python debug/verify_project.py97```98 99### Run FastAPI100 101```bash102uvicorn app.main:app --host 127.0.0.1 --port 8000103```104 105---106 107## Outputs (default locations)108 109| Step | Output |110|------|--------|111| `build_answers_v2` | `backend/data/AnswersV2.csv` |112| `build_final_dataset` | `backend/data/final_chatbot_data.csv` |113| `build_retrieval_artifacts` | `backend/artifacts/vectorizer.pkl`, `question_vectors.pkl`, `chatbot_df.pkl` |114 115The API loads **only** the three files under **`backend/artifacts/`** at startup.116 117---118 119## Troubleshooting (paths and startup)120 121- **`ModuleNotFoundError: app`** — Run `uvicorn` with the **current working directory** set to `backend/` (see above). The `app` package lives at `backend/app/`.122- **`Missing required retrieval artifact(s)`** — Run the build pipeline so `backend/artifacts/` contains `vectorizer.pkl`, `question_vectors.pkl`, and `chatbot_df.pkl`. Confirm with `python backend/debug/verify_project.py` from the project root.123- **`input file not found` / missing CSV** — Ensure `pybot_data/Answers.csv` exists for `build_answers_v2`, and `pybot_data/Questions.csv` for `build_final_dataset`. Ensure `backend/data/AnswersV2.csv` exists before `build_final_dataset` (run `build_answers_v2` first).124- **Wrong working directory** — Build and debug scripts use **script-relative paths**; you can run them from any cwd. For **Uvicorn**, cwd must be `backend/` so `app.main:app` resolves.125- **Port in use** — Change the port, e.g. `--port 8001`.126 