|
| 1 | +# Political Education Chatbot - UIT |
| 2 | + |
| 3 | +## Overview |
| 4 | +An AI-powered chatbot designed to answer questions about political and philosophical subjects in Vietnamese education. It is built with a FastAPI backend and a vanilla JavaScript frontend. |
| 5 | + |
| 6 | +## Features |
| 7 | + |
| 8 | +### Frontend |
| 9 | +- Real-time chat interface for seamless interaction. |
| 10 | +- PDF file upload functionality with progress tracking. |
| 11 | +- Visual feedback for various processing states. |
| 12 | +- Responsive design ensuring compatibility across devices. |
| 13 | + |
| 14 | +### Backend |
| 15 | +- Efficient PDF processing and knowledge extraction. |
| 16 | +- BM25 ranking algorithm for determining context relevance. |
| 17 | +- FAISS vector store for similarity-based searches. |
| 18 | +- Integration with Google Gemini 1.5 Pro for advanced AI responses. |
| 19 | + |
| 20 | +## Tech Stack |
| 21 | +- **Backend**: FastAPI, LangChain, FAISS, Sentence Transformers |
| 22 | +- **Frontend**: HTML5, CSS3, JavaScript |
| 23 | +- **AI**: Google Generative AI (Gemini 1.5 Pro) |
| 24 | + |
| 25 | +## Installation |
| 26 | + |
| 27 | +### Backend Setup |
| 28 | +1. Install Python dependencies: |
| 29 | + ```bash |
| 30 | + pip install -r requirements.txt |
| 31 | + ``` |
| 32 | + |
| 33 | +2. Start the FastAPI server: |
| 34 | + ```bash |
| 35 | + uvicorn app:app --reload --port 8000 |
| 36 | + ``` |
| 37 | + |
| 38 | +3. (Optional) Serve the frontend: |
| 39 | + ```bash |
| 40 | + python -m http.server 8080 |
| 41 | + ``` |
| 42 | + Alternatively, open `index.html` in a browser. |
| 43 | + |
| 44 | +## Usage |
| 45 | + |
| 46 | +1. Start the backend server. |
| 47 | +2. Open the frontend interface in your browser. |
| 48 | +3. (Optional) Upload PDF files to enrich the chatbot's knowledge base. |
| 49 | +4. Type questions into the chat input field. |
| 50 | +5. Receive detailed, AI-generated answers. |
| 51 | + |
| 52 | +## API Endpoints |
| 53 | + |
| 54 | +### Upload PDF |
| 55 | +- **Endpoint**: `POST /upload` |
| 56 | +- **Description**: Accepts PDF files for processing and adds their content to the knowledge base. |
| 57 | +- **Response**: Returns the processing status. |
| 58 | +- **Note**: Includes a 30-second processing delay to ensure thorough extraction. |
| 59 | + |
| 60 | +### Ask Question |
| 61 | +- **Endpoint**: `POST /answer` |
| 62 | +- **Request Body**: |
| 63 | + ```json |
| 64 | + { |
| 65 | + "query": "Your question", |
| 66 | + "use_external_knowledge": true |
| 67 | + } |
| 68 | + ``` |
| 69 | +- **Response**: Provides the AI-generated answer along with the inference time. |
| 70 | + |
| 71 | +## UI Components |
| 72 | +- **Chat Header**: Displays the chatbot's title and logo for easy identification. |
| 73 | +- **Message History Display**: Shows a chronological history of the conversation. |
| 74 | +- **File Upload Section**: Enables users to upload PDFs with progress indicators for real-time updates. |
| 75 | +- **Question Input**: Includes a text box and send button for submitting queries. |
| 76 | + |
| 77 | +## Environment Variables |
| 78 | +- `GOOGLE_API_KEY`: Your Google API key for integrating Gemini 1.5 Pro. |
| 79 | + |
| 80 | +## Development |
| 81 | +This chatbot was developed at the University of Information Technology - VNUHCM to enhance learning and engagement in political and philosophical education. |
| 82 | + |
0 commit comments