A conversational question-answer chatbot built with Streamlit and Google's Gemini Pro API. The chatbot automatically saves all conversations and displays them in a beautiful chat interface.
- 💬 Conversational Q&A chatbot using Gemini Pro
- 💾 Automatic chat history saving (JSON format)
- 📜 Display complete chat history in the UI
- 🗑️ Clear chat history option
- 📥 Download chat history as JSON
- 🔒 Secure API key management
First, activate your virtual environment and install the required packages:
# Activate virtual environment (Windows)
.venv\Scripts\activate
# Install dependencies
uv pip install -r requirements.txt- Visit Google AI Studio
- Sign in with your Google account
- Click "Create API Key"
- Copy your API key
You have two options:
Option A: Environment Variable (Recommended)
- Create a
.envfile in the project root - Add your API key:
GEMINI_API_KEY=your_api_key_here
Option B: Sidebar Input
- Run the app and enter your API key in the sidebar
streamlit run chatbot.pyThe app will open in your default web browser at http://localhost:8501
- Enter your Gemini API key (if not set in
.env) - Start chatting by typing your question in the chat input
- The chatbot will respond using Gemini Pro
- All conversations are automatically saved to
chat_history.json - Chat history persists across sessions
- Chat History: All conversations are saved in
chat_history.jsonin the project folder - Clear History: Use the "Clear Chat History" button in the sidebar to reset
- Download History: Download your chat history as a JSON file
- Timestamps: Each message includes a timestamp for reference
Project1/
├── .venv/ # Virtual environment
├── chatbot.py # Main Streamlit application
├── requirements.txt # Python dependencies
├── chat_history.json # Saved chat history (auto-generated)
├── .env # API key configuration (optional)
└── README.md # This file
- Python 3.8+
- Streamlit
- google-generativeai
- python-dotenv
- The chat history is saved locally in JSON format
- API key is stored securely (not in code)
- The chatbot uses Gemini Pro model with optimized settings
- All conversations include timestamps