Spaces:
Running
Running
title: Chat | |
emoji: 🦀 | |
colorFrom: pink | |
colorTo: red | |
sdk: streamlit | |
sdk_version: 1.44.1 | |
app_file: app.py | |
pinned: false | |
short_description: llamaindex streamlit chat demo | |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference | |
# Document Chatbot | |
A conversational AI chatbot for querying documents using LlamaIndex + Anthropic Claude. | |
## Features | |
- Load and index multiple document formats | |
- Conversational chat interface powered by Claude | |
- Memory optimization for multi-user environments | |
- Admin interface for document management and index control | |
## Setup | |
1. Clone this repository | |
2. Install dependencies: `pip install -r requirements.txt` | |
3. Copy `.env.example` to `.env` and add your Anthropic API key | |
4. Place documents in the `data` directory | |
## Memory Optimization Features | |
This application is optimized for memory efficiency, especially in multi-user environments: | |
- Shared resources across sessions: The language model, embedding model, and index are loaded once and shared across all user sessions | |
- Single instances of large models: Models are cached at application start rather than per-user | |
- Efficient index loading: The document index is loaded once and reused for all users | |
- Limited message history: The application limits the number of messages kept in memory to prevent memory leaks | |
## Running the Applications | |
This is a multi-page Streamlit application with two main interfaces: | |
### User Interface (Main Page) | |
``` | |
streamlit run Public_Chat.py | |
``` | |
This is the main chat interface where users can ask questions about the documents. | |
### Admin Interface (Pages) | |
The admin interface is automatically available as a page in the sidebar. When running the application, you'll see a sidebar with navigation options. Click on "Admin" to access the admin interface. | |
The admin interface allows you to: | |
- Upload and manage documents | |
- Rebuild or update the document index | |
- Configure application settings | |
Password for admin interface: `admin` (can be changed in secrets.toml) | |
### Page Naming Convention | |
The application uses Streamlit's multi-page naming convention: | |
- The main file (`Public_Chat.py`) appears as "Public Chat" in the sidebar | |
- Pages in the `pages` directory follow the pattern `NN_PageName.py` where: | |
- `NN` is an optional number for ordering pages | |
- `PageName` is automatically converted to "Page Name" in the sidebar | |
- Example: `01_Admin.py` displays as "Admin" in the sidebar | |
### Backend CLI (Optional) | |
``` | |
python backend.py | |
``` | |
This runs the backend directly from the command line, useful for testing and development. | |
## Troubleshooting | |
If you experience issues with imports or module reloading: | |
1. Clear Python cache files: | |
``` | |
find . -name __pycache__ -type d -exec rm -rf {} + | |
``` | |
2. Use force-reload when starting Streamlit: | |
``` | |
streamlit run Public_Chat.py --server.runOnSave=true | |
``` | |
See [DEPLOYMENT.md](DEPLOYMENT.md) for cloud deployment options. | |
## Feedback System (Updated) | |
- User feedback is now stored in a Supabase database for persistent, structured storage and future analytics. | |
- Due to issues with Supabase Row Level Security (RLS) and the anon key, the application currently uses the Supabase service (admin) key to insert feedback. This bypasses RLS and allows all feedback to be saved securely from the backend. | |
- **Note:** Using the service key is a workaround. For production, consult Supabase support or documentation to implement a more secure, best-practice solution for public/anon feedback collection. | |
## Progress | |
- Feedback database integration with Supabase is complete and operational. | |
- All feedback fields are now saved and can be reviewed in the Supabase dashboard. |