Spaces:
Build error
Build error
Update README.md
#17
by mukiibi - opened
README.md
CHANGED
|
@@ -1,12 +1,107 @@
|
|
| 1 |
-
--
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ASKXENO - AI-Powered XENO Support Assistant
|
| 2 |
+
Overview
|
| 3 |
+
ASKXENO is an AI-powered customer support assistant designed to provide accurate and timely responses to queries about XENO financial services. Built with a Retrieval-Augmented Generation (RAG) pipeline, it leverages a knowledge base, intent classification, and conversation memory to deliver professional and context-aware responses. The application is deployed as a Hugging Face Space and includes performance tracking for response time analysis.
|
| 4 |
+
Features
|
| 5 |
+
|
| 6 |
+
Natural Language Query Handling: Responds to user questions about XENO services, including account management, transactions, platform features, and general information.
|
| 7 |
+
Intent Classification: Detects simple intents (e.g., greetings, thanks, goodbyes) for quick, tailored responses without querying the knowledge base.
|
| 8 |
+
RAG Pipeline: Uses a ChromaDB vector store and Google Gemini embeddings to retrieve relevant information from a JSON-based XENO knowledge base.
|
| 9 |
+
Conversation Memory: Maintains chat history using LangGraph's SqliteSaver for context-aware responses.
|
| 10 |
+
Performance Tracking: Logs response times for each processing step (e.g., intent classification, retrieval, LLM generation) to a Google Sheet for analysis.
|
| 11 |
+
Gradio UI: Provides an interactive, user-friendly interface with session tracking and a chatbot-style conversation display.
|
| 12 |
+
Error Handling: Includes robust logging to handle and record errors, with fallback local file logging if Google Sheets fails.
|
| 13 |
+
|
| 14 |
+
Tech Stack
|
| 15 |
+
|
| 16 |
+
Python Libraries:
|
| 17 |
+
gradio: For the web-based user interface.
|
| 18 |
+
pandas: For handling the JSON knowledge base.
|
| 19 |
+
sentence_transformers: For similarity calculations.
|
| 20 |
+
google.generativeai: For embeddings and LLM responses (Gemini API).
|
| 21 |
+
chromadb: For vector storage and retrieval.
|
| 22 |
+
langchain_chroma: For integrating ChromaDB with LangChain.
|
| 23 |
+
gspread: For logging to Google Sheets.
|
| 24 |
+
langgraph: For conversation memory management.
|
| 25 |
+
torch: For tensor operations in similarity calculations.
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Database:
|
| 29 |
+
SQLite for conversation memory (xeno_memory.db).
|
| 30 |
+
ChromaDB for persistent vector storage (/tmp/xeno_db).
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
External Services:
|
| 34 |
+
Google Sheets for logging responses and timing data.
|
| 35 |
+
Google Gemini API for embeddings and text generation.
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
Setup and Installation
|
| 40 |
+
This project is designed to run in a Hugging Face Space. To set it up locally or in a similar environment, follow these steps:
|
| 41 |
+
|
| 42 |
+
Clone the Repository (if not running in Hugging Face Space):
|
| 43 |
+
git clone <repository-url>
|
| 44 |
+
cd <repository-directory>
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
Install Dependencies:Ensure Python 3.8+ is installed, then install the required packages:
|
| 48 |
+
pip install -r requirements.txt
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
Set Environment Variables:
|
| 52 |
+
|
| 53 |
+
GEMINI_API_KEY: Your Google Gemini API key.
|
| 54 |
+
GOOGLE_SHEETS_CREDENTIALS: JSON credentials for Google Sheets API access.Example:
|
| 55 |
+
|
| 56 |
+
export GEMINI_API_KEY="your-api-key"
|
| 57 |
+
export GOOGLE_SHEETS_CREDENTIALS='{"type": "service_account", ...}'
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
Prepare Knowledge Base:
|
| 61 |
+
|
| 62 |
+
Ensure XENO Uganda_KnowlegeBase_V1.json is in the project root.
|
| 63 |
+
The JSON file should contain entries with Question, Content, ID, and optional fields like Section, Source, Owner, and Tag.
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
Run the Application:
|
| 67 |
+
python app.py
|
| 68 |
+
|
| 69 |
+
The Gradio interface will be available at http://0.0.0.0:7860.
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
Usage
|
| 73 |
+
|
| 74 |
+
Access the Interface: Open the Hugging Face Space URL or local server URL in a browser.
|
| 75 |
+
Interact with the Chatbot:
|
| 76 |
+
Enter a session ID (or use the auto-generated UUID).
|
| 77 |
+
Type your question in the text box and click "Send" or press Enter.
|
| 78 |
+
The assistant responds based on the knowledge base or intent classification.
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
View Logs:
|
| 82 |
+
Response logs are stored in the "Response_Log" sheet of the configured Google Sheet.
|
| 83 |
+
Timing data (e.g., total time, step-wise breakdowns) is logged in the "Timing_Log" sheet.
|
| 84 |
+
Local fallback logs are saved in /tmp/response_log.txt and /tmp/timing_log.txt if Google Sheets fails.
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
Performance Tracking
|
| 89 |
+
The application logs detailed timing data for each request, including:
|
| 90 |
+
|
| 91 |
+
Intent classification
|
| 92 |
+
Memory retrieval
|
| 93 |
+
RAG retrieval
|
| 94 |
+
Embedding generation
|
| 95 |
+
Similarity calculation
|
| 96 |
+
Context processing
|
| 97 |
+
LLM generation
|
| 98 |
+
Memory update
|
| 99 |
+
Response logging
|
| 100 |
+
|
| 101 |
+
This data is useful for analyzing system performance and identifying bottlenecks. Check the "Timing_Log" sheet for detailed metrics.
|
| 102 |
+
Limitations
|
| 103 |
+
|
| 104 |
+
Knowledge Base Dependency: Responses are limited to the information in XENO Uganda_KnowlegeBase_V1.json. If no relevant information is found (similarity score < 0.4), the assistant politely declines to answer.
|
| 105 |
+
API Dependency: Requires a stable connection to the Google Gemini API and Google Sheets.
|
| 106 |
+
Hugging Face Space Constraints: Resource limitations (e.g., storage, compute) may affect performance in a shared environment.
|
| 107 |
+
Language Support: Currently optimized for English queries.
|