A real-time AI-powered customer support chatbot built with Google Gemini API and FastAPI. Features streaming responses, conversation memory, smart escalation to human agents, and a modern web UI.
- Real-time Streaming — Responses appear token-by-token, just like ChatGPT
- Knowledge Base — Answers questions from a configurable FAQ database
- Conversation Memory — Maintains context across messages within a session
- Smart Escalation — Detects frustrated customers and escalates to human agents
- Modern UI — Clean interface built with Tailwind CSS and Material Design icons
- Markdown Rendering — AI responses support bold, lists, code blocks, and more
- Session Management — Multiple users can chat simultaneously
- Backend: Python, FastAPI, Uvicorn
- AI: Google Gemini 2.5 Flash via
google-genaiSDK - Frontend: HTML, Tailwind CSS, Vanilla JavaScript, marked.js
- Streaming: Server-Sent Events (SSE)
portfolio-chatbot/
├── server.py # FastAPI backend with API endpoints and SSE streaming
├── chatbot.py # Gemini API integration, streaming, and escalation logic
├── config.py # System prompt, FAQ knowledge base, and company config
├── index.html # Frontend UI with chat interface and sidebar
├── app.py # Alternative Streamlit UI (legacy)
├── .env # API key (not committed)
└── requirements.txt # Python dependencies
git clone https://github.com/RohanKatara/AI-chatbot.git
cd AI-chatbotpip install -r requirements.txtCreate a .env file in the project root:
GEMINI_API_KEY=your_api_key_here
Get your API key from Google AI Studio.
uvicorn server:app --host 0.0.0.0 --port 8000Visit http://localhost:8000
- User sends a message from the browser
- FastAPI receives the request and forwards it to the Gemini API
- Gemini generates a response using the system prompt + FAQ knowledge base + conversation history
- Response is streamed back token-by-token via Server-Sent Events (SSE)
- Frontend renders each chunk in real-time with Markdown support
- If escalation triggers are detected (e.g., "speak to a human"), the chat is escalated
To adapt this chatbot for a different business:
config.py— UpdateCOMPANY_NAME,COMPANY_DESCRIPTION, andFAQ_DATAconfig.py— Modify theSYSTEM_PROMPTfor different tone/rulesindex.html— Change branding, colors, and layout.env— Use your own Gemini API key
GET /— Serves the chat UIPOST /api/chat— Send a message, receive streaming AI responsePOST /api/new-session— Create a new chat sessionGET /api/faq— Get the FAQ knowledge baseGET /api/status— Get AI agent statusGET /api/escalation— Get escalation rules and triggersGET /api/memory/{session_id}— Get conversation history
MIT