CoolFace
Apppublic

Rxrohans/PayLens-Dev

sourceHugging Facemitupdated 7mo agoView on Hugging Face
0likes
App README

<div align="center">

πŸ’³ PayLens

AI-powered payment fee explainer

![Live Demo](https://huggingface.co/spaces/Rxrohans/paylens) ![Python](https://python.org) ![LangChain](https://langchain.com) ![Groq](https://groq.com) ![License](LICENSE)

"Why did PayPal deduct 7% from my payment?" β€” PayLens tells you exactly why, and what to do about it.

[β†’ Try the live demo](https://huggingface.co/spaces/Rxrohans/paylens)

</div>


🎯 The Problem

You see USD 500 in your PayPal. Quick mental math β€” that's around β‚Ή41,500 at today's rate. You're happy. Then the money actually arrives. β‚Ή38,200. You got β‚Ή3,300 less and you have no idea why. Transaction fee? Currency conversion markup? Some hidden platform charge? The app doesn't explain it clearly. The terms are a bit complex. You're just... sad. PayLens tells you exactly what happened β€” how much each platform deducted, why, and what you can do differently next time.

PayLens solves this. Just Ask, get a clear answer

Example questions it answers:

  • β€”"Why did PayPal charge me 7-8% when I received money from Outlier?"
  • β€”"What is the difference between NEFT and IMPS?"
  • β€”"Do I need to pay GST on my freelance income from abroad?"
  • β€”"How does currency conversion spread work?"
  • β€”"Is UPI free for merchants in India?"

πŸ—οΈ System Architecture

User Question
      ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  INPUT GUARDRAILS           β”‚
β”‚  β€’ PII detection            β”‚
β”‚  β€’ Prompt injection check   β”‚
β”‚  β€’ Topic relevance filter   β”‚
β”‚  β€’ Length validation        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  FAISS SEMANTIC RETRIEVAL   β”‚
β”‚  β€’ all-MiniLM-L6-v2 embeds  β”‚
β”‚  β€’ Top-7 chunk retrieval    β”‚
β”‚  β€’ Cosine similarity search β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      ↓
  Confidence score >= 0.60?
    β”‚                    β”‚
   YES                   NO
    β”‚                    ↓
    β”‚         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚         β”‚  DUCKDUCKGO SEARCH  β”‚
    β”‚         β”‚  Live web results   β”‚
    β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    β”‚                    β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  LLM SYNTHESIS              β”‚
β”‚  β€’ Llama 3.1 via Groq       β”‚
β”‚  β€’ Two prompt variants      β”‚
β”‚    (RAG-only / Hybrid)      β”‚
β”‚  β€’ temperature=0            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  OUTPUT GUARDRAILS          β”‚
β”‚  β€’ Hallucination detection  β”‚
β”‚  β€’ PII redaction from logs  β”‚
β”‚  β€’ Confidence classificationβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      ↓
  Structured Answer
  + Source badges
  + Confidence badge
  + Official links
  + JSONL audit log

✨ Features

Core

FeatureDetails
Hybrid RAGFAISS semantic search with DuckDuckGo live web fallback β€” triggers when KB confidence score < 0.60
Rich Knowledge Base150+ chunks across 6 domain files covering payments, forex, taxes, regulations
Structured OutputEvery answer includes confidence level, source attribution, latency, and official links
Audit LoggingEvery query logged to JSONL with question, answer, sources, latency, confidence, PII flags

Safety & Compliance

FeatureDetails
PII DetectionRegex patterns for Aadhaar, PAN, card numbers, UPI IDs, email, phone β€” sanitized before logging
Prompt Injection BlockingPattern matching against known injection attempts
Topic GuardrailsOff-topic questions (cricket scores, geography, etc.) blocked with explanation
Hallucination SignalsOutput scanner detects and flags potential hallucination patterns

Evaluation

FeatureDetails
Golden Dataset20 manually verified Q&A pairs covering all KB domains
Custom Eval PipelineKeyword overlap scoring β€” faithfulness, relevancy, context coverage
Score HistoryEvery eval run saved to JSON β€” track quality changes over time
Dashboard TabBuilt-in Streamlit eval tab shows scores, trends, per-sample breakdown

🧠 Knowledge Base

6 curated domain files totalling 150+ indexed chunks:

FileWhat it covers
payment_fees_manual.txtPayPal India, Stripe India, Razorpay fees β€” transaction fees, dispute fees, conversion spreads
fintech_fundamentals.txtHow payments work end-to-end, UPI/NEFT/IMPS/RTGS/SWIFT, card networks, MDR, PCI-DSS, chargebacks
forex_economics.txtExchange rates, bid/ask spread, FEMA rules, LRS scheme, why INR weakens, PPP
india_tax_compliance.txtGST on payment fees, TDS, TCS on foreign remittances, ITR filing for freelancers, FIRC
paypal_fees_india.txtScraped PayPal India pricing page
stripe_pricing_india.txtScraped Stripe India pricing page

All sources documented in `data/SOURCES.md`.

Live web search (DuckDuckGo) handles questions outside the KB β€” no API key required.


πŸ› οΈ Tech Stack

ComponentTechnologyWhy
LLMLlama 3.1 8B Instant via GroqFree tier (14,400 req/day), fastest inference
Embeddingsall-MiniLM-L6-v2Local, 384-dim, good quality/speed tradeoff
Vector StoreFAISS IndexFlatIPCosine similarity, in-memory, no server needed
RAG FrameworkLangChain LCELModular chain composition
Web SearchDuckDuckGo (ddgs)Free, no API key, no restrictions
GuardrailsCustom (regex + pattern matching)Full control, no external dependency
EvaluationCustom keyword overlapZero LLM calls, rate-limit safe
UIStreamlitRapid deployment, HuggingFace native
DeploymentHuggingFace Spaces (Docker)Free, public URL, auto-deploy on push
Version ControlGit + GitHubBranch-based workflow

πŸ“Š Evaluation Results

First eval run β€” 20 questions, March 2026

MetricScoreWhat it measures
Context Coverage62.81%Retriever finding right documents
Faithfulness14.63%Answer grounded in retrieved context*
Answer Relevancy12.70%Answer addresses the question*
Avg Latency~600ms (RAG) / ~2500ms (hybrid)Response time
Web Search Rate45% of queriesHybrid fallback trigger rate
Confidence Dist90% High, 10% MediumLLM self-assessed confidence

Note: Faithfulness and Relevancy use keyword overlap scoring which underreports paraphrasing LLMs. A human evaluation of the same answers would score significantly higher. Context Coverage is the most reliable metric for this system.

Run your own evaluation:

bash
python eval/ragas_eval.py

πŸ“ Project Structure

paylens/
β”‚
β”œβ”€β”€ src/                          ← Python source
β”‚   β”œβ”€β”€ app.py                    ← Streamlit UI (tabs: Ask / Eval Dashboard)
β”‚   β”œβ”€β”€ chain.py                  ← Hybrid RAG + web search logic
β”‚   β”œβ”€β”€ retriever.py              ← FAISS semantic search
β”‚   β”œβ”€β”€ embedder.py               ← Builds vector store from chunks
β”‚   β”œβ”€β”€ chunker.py                ← Splits raw docs into chunks with metadata
β”‚   β”œβ”€β”€ ingestor.py               ← Fetches/loads raw documents
β”‚   └── guardrails.py             ← PII detection + injection prevention
β”‚
β”œβ”€β”€ eval/                         ← Evaluation pipeline
β”‚   β”œβ”€β”€ ragas_eval.py             ← Runs eval, saves scores
β”‚   β”œβ”€β”€ metrics_dashboard.py      ← Dashboard UI (embedded as app tab)
β”‚   β”œβ”€β”€ golden_dataset.json       ← 20 verified Q&A pairs
β”‚   └── scores_history.json       ← Score history (auto-generated)
β”‚
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ raw/                      ← Knowledge base source files 
β”‚   β”œβ”€β”€ processed/                ← Auto-generated, gitignored
β”‚   β”‚   β”œβ”€β”€ chunks.json           ← Chunked documents with metadata
β”‚   β”‚   β”œβ”€β”€ faiss_index.bin       ← FAISS vector index
β”‚   β”‚   └── chunk_metadata.pkl    ← Chunk source/score metadata
β”‚   └── SOURCES.md                ← Data lineage registry
β”‚
β”œβ”€β”€ logs/                         ← Auto-generated, gitignored
β”‚   β”œβ”€β”€ answers.jsonl             ← Full audit log of every query
β”‚   └── chain.log                 ← System logs
β”‚
β”œβ”€β”€ .gitignore                    ← Excludes venv, .env, index, logs
β”œβ”€β”€ .env                          ← API keys (gitignored)
β”œβ”€β”€ env.example                   ← Safe template for .env
β”œβ”€β”€ requirements.txt              ← Python dependencies
β”œβ”€β”€ packages.txt                  ← HuggingFace Linux deps (libgomp1)
└── README.md                     ← This file (also HuggingFace Space config)

πŸš€ Run Locally

bash
# 1. Clone
git clone https://github.com/Rxrohans/paylens
cd paylens

# 2. Create virtual environment
python -m venv venv
venv\Scripts\activate      # Windows
# source venv/bin/activate  # Mac/Linux

# 3. Install dependencies
pip install -r requirements.txt

# 4. Add your free Groq API key
# Get one at: console.groq.com (free, no credit card)
cp env.example .env
# Edit .env: GROQ_API_KEY=your_key_here

# 5. Build knowledge base index
python src/chunker.py
python src/embedder.py

# 6. Launch
streamlit run src/app.py
# Opens at http://localhost:8501

πŸ”„ Adding New Knowledge

No code changes needed:

bash
# 1. Add your .txt file
nano data/raw/new_topic.txt

# 2. Document it
nano data/SOURCES.md

# 3. Rebuild index (2 commands)
python src/chunker.py
python src/embedder.py

# New knowledge is live immediately

πŸ”§ Swapping the LLM

One line change in src/chain.py:

python
# Current (fastest, 14,400 req/day free)
model="llama-3.1-8b-instant"

# Smarter answers (1,000 req/day free)
model="llama-3.3-70b-versatile"

# Latest Llama 4 (1,000 req/day free)
model="meta-llama/llama-4-scout-17b-16e-instruct"

πŸ—ΊοΈ Roadmap

  • β€”[ ] Section-header based chunking (better than fixed-size for structured docs)
  • β€”[ ] Embedding similarity eval (more accurate than keyword overlap)
  • β€”[ ] Paytm, CCAvenue, PayU fee structures
  • β€”[ ] Southeast Asia + Middle East payment systems (Pine Labs markets)
  • β€”[ ] Conversation memory for multi-turn questions
  • β€”[ ] Query latency optimisation (cache frequent questions)
  • β€”[ ] Cost tracking per query

πŸ‘€ Author

Rohan Singh

![GitHub](https://github.com/Rxrohans) ![HuggingFace](https://huggingface.co/Rxrohans)


πŸ“„ License

MIT β€” see LICENSE for details.