This is a sophisticated RAG (Retrieval-Augmented Generation) chatbot for apartment rentals with dual interfaces:
- Interactive Mode: Terminal-based chat
- Web Mode: Beautiful Streamlit web interface
pip install streamlit google-genai chromadb pymongo python-dotenv sentence-transformersCreate a .env file in your project root with the following content:
# API Keys
GEMINI_API_KEY="your_gemini_api_key"
GEMINI_MODEL_NAME="gemini-2.5-flash-lite"
# MongoDB Configuration
MONGO_URI="your_mongodb_uri"
MONGO_DB_NAME="chat_sessions"
MONGO_COLLECTION_NAME="chatbot_context"
# ChromaDB Configuration
CHROMA_DB_PATH="./chroma_storage"
CHROMA_COLLECTION_NAME="json_docs"
CHROMA_EMBEDDING_MODEL_NAME="all-MiniLM-L6-v2"
# Data Configuration
JSON_FILE_PATH="./data_ingestion/apartments.json"
# Application Configuration
DEFAULT_USER_ID="default_user"
RAG_CONTEXT_LIMIT="5"
APP_MODE=web
WEB_HOST="127.0.0.1"
WEB_PORT="8501"1. Start the FastAPI backend:
uvicorn api_server:app --host 127.0.0.1 --port 8000 --reload2. Start the Streamlit frontend:
streamlit run frontend/app.py --server.port 8501Make sure your .env has APP_MODE=web.
Open: http://127.0.0.1:8501 in your browser.
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ User Query │───▶│ ChromaDB │───▶│ Context │
│ │ │ (Apartments) │ │ Retrieved │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│
┌─────────────────┐ ┌──────────────────┐ ▼
│ Final │◀───│ Gemini AI │◀───┌─────────────────┐
│ Response │ │ Generation │ │ Enhanced │
└─────────────────┘ └──────────────────┘ │ Prompt │
│ └─────────────────┘
▼ ▲
┌─────────────────┐ ┌──────────────────┐ │
│ MongoDB │◀───│ Conversation │────────────┘
│ Storage │ │ History │
└─────────────────┘ └──────────────────┘
- ✅ Real-time chat interface with message bubbles
- ✅ Session management with user/session IDs
- ✅ Sidebar with controls and system status
- ✅ Responsive design for mobile/desktop
- ✅ Custom CSS styling with gradients
- ✅ Loading indicators and error handling
- ✅ New Session: Start fresh conversation
- ✅ Clear Chat: Remove history from UI and database
- ✅ System Status: Check component health
- ✅ Example Queries: Quick-start with sample questions
- ✅ Auto-scroll: Latest messages always visible
- User ID and Session ID display
- Message count tracking
- Connection status indicator
- Real-time updates
- First Run: Automatically loads
apartments.jsoninto ChromaDB - Subsequent Runs: Skips loading if data already exists
- Persistent Storage: Data survives application restarts
Switch between modes by changing the APP_MODE environment variable:
# Interactive mode
export APP_MODE="interactive"
python main.py
# Web mode (Streamlit)
export APP_MODE="web"
python main.py- Simpler Development: No HTML/CSS/JavaScript needed
- Built for AI: Perfect for chatbots and ML applications
- Native Chat Support: Built-in chat message handling
- Rapid Prototyping: Get beautiful UI in minutes
- Session Management: Built-in session state handling
- Live Updates: Auto-refresh and real-time updates
- Chat interfaces are first-class citizens
- Easy data visualization and status display
- Simple deployment and sharing
- Great for internal tools and demos
- Import Error:
pip install streamlit - Port Conflict: Change
WEB_PORTin .env - Database Connection: Check MongoDB URI
- API Limits: Verify Gemini API key
- Browser not opening: Use
--server.headless true - Port issues: Use
--server.port XXXX - Performance: Use
st.cache_data()for large data
- Edit CSS in
frontend/app.py - Use
st.markdown()with custom CSS - Modify color schemes and layouts
- File upload for apartment data
- Charts and visualizations
- Export conversation history
- Multi-language support
streamlit run frontend/app.py- Push to GitHub
- Connect repository to Streamlit Cloud
- Deploy with one click