CoolFace
Apppublic

nate149/rural-mortgage-bot-api

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
App README

\# Rural Mortgage Research Bot

An AI agent for researching rural mortgage options (USDA, FHA, VA), built with LangGraph + Streamlit.

\## Features

\- ๐Ÿ” RAG over USDA/FHA/VA handbooks (Pinecone vector store)

\- ๐ŸŒพ Combined CFPB + USDA rural eligibility lookup (zip or address)

\- ๐Ÿฆ HMDA lender search by loan type, construction method, county

\- ๐Ÿ’ฐ Mortgage payment \& affordability calculators

\- ๐Ÿ“ Census Bureau geocoding (free, no key)

\## Setup

\### 1. Clone and create venv

bash

git clone https://github.com/YOUR-USERNAME/rural-mortgage-bot.git

cd rural-mortgage-bot

python -m venv venv

source venv/Scripts/activate    # Windows Git Bash

\# OR:  source venv/bin/activate  # Mac/Linux

pip install -r requirements.txt



2\. Get API keys



OpenAI: https://platform.openai.com/api-keys

Pinecone: https://app.pinecone.io

Census (free): https://api.census.gov/data/key\_signup.html



3\. Create .env in project root



OPENAI\_API\_KEY=sk-proj-...

PINECONE\_API\_KEY=pcsk\_...

PINECONE\_INDEX\_NAME=rural-mortgage

CENSUS\_API\_KEY=...



4\. Download reference datastreamlit run app.py



mkdir -p data/reference

curl -L -o data/reference/cfpb\_rural\_counties.csv \\

  "https://files.consumerfinance.gov/f/documents/cfpb\_rural-or-underserved-counties\_2024.csv"



5\. Build the Knowledge Base (first time only)



python download\_pdfs.py

python ingest.py

python web\_ingest.py



6\. Run



streamlit run app.py


Data Sources

The bot draws from three categories of data: bundled PDFs, reference CSVs, and live APIs.

### ๐Ÿ“„ PDF handbooks (`data/pdfs/`)

USDA, FHA, and VA program handbooks plus rural reference materials. Total ~30MB.

**USDA Section 502 Direct (Handbook 3550-1)**
- `3550-1chapter01.pdf` โ€” Overview
- `3550-1chapter02.pdf` โ€” Record Retention
- `3550-1chapter03.pdf` โ€” Lender Approval
- `3550-1chapter04.pdf` โ€” Borrower Eligibility
- `3550-1chapter05.pdf` โ€” Property Requirements
- `3550-1chapter06.pdf` โ€” Loan Purposes
- `3550-1chapter07.pdf` โ€” Loan Terms
- `3550-1chapter08.pdf` โ€” Application Processing
- `3550-1chapter09.pdf` โ€” Loan Approval
- `3550-1chapter10.pdf` โ€” Loan Closing

**USDA Section 502 Guaranteed (Handbook 3555-1)**
- `3555-1chapter01.pdf` โ€” Overview
- `3555-1chapter03.pdf` โ€” Lender Approval
- `3555-1chapter04.pdf` โ€” Lender Responsibilities
- `3555-1chapter05.pdf` โ€” Origination
- `3555-1chapter06.pdf` โ€” Loan Purposes
- `3555-1chapter07.pdf` โ€” Loan Terms
- `3555-1chapter08.pdf` โ€” Applicant Characteristics
- `3555-1chapter09.pdf` โ€” Income Analysis
- `3555-1chapter10.pdf` โ€” Credit Analysis
- `3555-1chapter11.pdf` โ€” Ratio Analysis
- `3555-1chapter15.pdf` โ€” Submitting the Application
- `3555-1chapter16.pdf` โ€” Closing

**FHA Single Family Housing**
- `40001-hsgh-Update-17.pdf` โ€” FHA Single Family Housing Policy Handbook 4000.1

**VA**
- `VA_Buyers_Guide.pdf` โ€” VA Home Loan Buyer's Guide

**USDA Reference**
- `RD-DirectLimitMap.pdf` โ€” USDA Direct Loan income limit map
- `RD-SFH-ManufacturedHousing1.pdf` โ€” USDA manufactured housing requirements

**CFPB Rural/Underserved (2026)**
- `cfpb_rural-list_2026.pdf`
- `cfpb_rural-underserved-list_2026.pdf`
- `cfpb_underserved-list_2026.pdf`

### ๐Ÿ“Š Reference CSVs (`data/reference/`)
- `cfpb_rural_counties.csv` โ€” CFPB rural/underserved county designations (machine-readable)

### ๐ŸŒ Ingested web pages
See `data/.ingested_urls.txt` for the list of program web pages scraped by `web_ingest.py`.

### ๐Ÿ”Œ Live APIs (no local data needed)
| Source | Use |
|---|---|
| **Pinecone** | Vector store for RAG search over PDFs and web content |
| **OpenAI** | Embeddings (`text-embedding-3-large`) and chat (`gpt-4o`) |
| **Census Bureau Geocoder** | Address โ†’ county FIPS, lat/lon (free, no key) |
| **Census Bureau ACS** | Place population estimates (free, requires API key) |
| **CFPB FFIEC HMDA Data Browser** | Lender activity by state/county/loan type (free, no key) |

### Re-ingestion

To rebuild the knowledge base from scratch:

python downloadpdfs.py # Downloads any missing PDFs python ingest.py # Embeds and uploads PDFs to Pinecone python webingest.py # Scrapes and ingests web pages

Architecture

app.py โ€” Streamlit UI (chat + sidebar lookups)

agent.py โ€” LangGraph agent that routes between tools

tools.py โ€” All tool functions (RAG search, calculators, lookups, HMDA)

ingest.py / web\_ingest.py โ€” Data ingestion to Pinecone

download\_pdfs.py โ€” Downloads USDA/FHA/VA handbooks

DISCLAIMER

Research only. Not financial or legal advice.