CoolFace
Apppublic

sunkistCAT/standard_chartered_rag_demo

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
App README

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference

πŸ“Š Standard Chartered RAG Demo

Interact with financial reports or news articles using Google Gemini and Retrieval-Augmented Generation (RAG). Upload a document or paste text, then chat with Gemini for intelligent, concise answers.


✨ Features

  • β€”Upload financial documents (.pdf, .txt, .docx)
  • β€”Paste raw financial news or text
  • β€”Ask questions using Gemini via google-genai
  • β€”Automatic summary and character count for uploaded/pasted content
  • β€”Context-aware answers using RAG (PGVector + Gemini)
  • β€”"Clear Chat" resets all fields and context
  • β€”Built with Gradio UI

πŸ“‚ Folder Structure

standard_chartered_rag_demo/
β”œβ”€β”€ app.py
β”œβ”€β”€ handlers/
β”‚   β”œβ”€β”€ chat_handler.py
β”‚   β”œβ”€β”€ file_handler.py
β”‚   β”œβ”€β”€ text_handler.py
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ context_utils.py
β”‚   β”œβ”€β”€ db_service.py
β”‚   β”œβ”€β”€ gemini_service.py
β”œβ”€β”€ .env
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ README.md

πŸš€ Setup & Run

1. Install dependencies

bash
pip install -r requirements.txt

2. Configure environment

Create a .env file in the root directory with your API keys and database URL:

GEMINI_API_KEY=your-google-api-key
MODEL_3=gemini-2.5-flash-lite-preview-06-17
EMBEDDING_MODEL=gemini-embedding-001
SUPABASE_DB_URL=your-postgres-connection-string

3. Start the app

bash
python app.py

Open the link provided in the terminal.


🧠 Example Questions

After uploading or pasting content, try:

  • β€”What are the main risks mentioned?
  • β€”Summarize the Q1 financial highlights.
  • β€”What are the revenue growth drivers?
  • β€”Is there any forecast for the next quarter?
  • β€”What are the top risks mentioned in this report?
  • β€”Summarize the company’s performance this quarter.
  • β€”How did revenue change from the previous period?
  • β€”What risks are mentioned in this document?
  • β€”Summarize the financial highlights.
  • β€”What is the outlook for the next quarter?

πŸ§ͺ Notes

  • β€”Context is truncated to 30,000 characters to avoid overloading Gemini.
  • β€”Both file and text inputs have their own summaries and character counters.
  • β€”Uses PGVector for vector similarity search.
  • β€”Gradio UI for easy interaction.

πŸ“Œ Tech Stack

  • β€”Google Gemini (google-genai)
  • β€”Gradio
  • β€”Python (3.11+)
  • β€”PyMuPDF (fitz) for PDF parsing
  • β€”python-docx for Word files
  • β€”SQLAlchemy + PGVector for vector database

πŸ’‘ Future Improvements

  • β€”Authentication, permission handling (use case etc.)
  • β€”RAG optimization
  • β€”Late chunking
  • β€”Query transformation
  • β€”Use local model for compliance, and save cost
  • β€”Check document classification:
  • β€”Allow PUBLIC, INTERNAL
  • β€”Block RESTRICTED, HIGHLY RESTRICTED, or unclassified
  • β€”Model evaluation. # TODO: reference Warden
  • β€”Groundness
  • β€”Context relevance (when using RAG)
  • β€”Answer relevance
  • β€”Model moderation
  • β€”Fairness and bad actor
  • β€”prompt jailbreaking
  • β€”harmful content classifier
  • β€”Feedback service
  • β€”Allow user to submit feedback
  • β€”If a user copied a LLM response
  • β€”monolithic -> microservices
  • β€”Now: UI, business logic, data are all in one place