sunkistCAT/standard_chartered_rag_demo
0
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
pip install -r requirements.txt2. 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-string3. Start the app
python app.pyOpen 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-docxfor 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
