- GPT-powered chatbot that can handle general chat, code generation, and mathematical queries.
- Firebase Firestore integration to store and retrieve chat history.
- Streamlit web interface for a user-friendly interaction with the chatbot.
- Displays responses with typing effects, including Python code snippets.
Before running this project, make sure you have the following:
- Python 3.8 or higher installed.
- A Google Firebase account with Firestore enabled.
- A Google API key from ai.google.dev.
git clone https://github.com/yourusername/your-repo.git
cd your-repo
python -m venv venv
source venv/bin/activate # For Linux/macOS
venv\Scripts\activate # For Windows
pip install -r requirements.txt
- Create a Firebase project in the Firebase Console.
- Enable Firestore as your database.
- Create a Firebase service account key by navigating to Project Settings > Service Accounts. Download the JSON file and place it in the root directory of your project as
firebase_key.json
.
- Go to Google's AI Model API and create a new API key.
- Copy the API key and add it to the
.env
file.
- Create a
.env
file in the root directory with the following variables:API_KEY=your_gpt_api_key FIREBASE_KEY=path_to_firebase_key.json
-
Start the Streamlit app:
streamlit run main.py
-
This will open a web interface where you can start chatting with the AI bot.
main.py
: Handles Streamlit's front-end interface and chatbot functionality.backend.py
: Manages GPT API communication, Firebase interactions, and message processing.firebase_key.json
: Firebase service account configuration for Firestore access..env
: Stores environment variables, including API and Firebase keys.
- Click the "Start Chatting" button to load previous chat history from Firestore.
- Enter your prompt in the chat input field, and the bot will generate a response.
- The chatbot supports regular chat, math expressions, and code generation (Python).
- The chat history will be stored in Firebase, and previous interactions will be loaded when you reopen the app.
- Firebase Integration: Uses Firestore to store user prompts and bot responses.
- GPT Interaction: Sends user input to the Gemini AI model, processes the response, and handles different types of outputs (text, code, etc.).
- Streamlit Interface: Displays a user-friendly chat interface where you can input messages and view responses.
- Message Handling: Processes user inputs and responses, including displaying Python code if generated by the AI.
Once the chatbot is running, it can handle interactions like:
User: "Can you write a Python program to add two numbers?"
Bot:
def add_two_numbers(num1, num2):
return num1 + num2
number1 = float(input("Enter the first number: "))
number2 = float(input("Enter the second number: "))
result = add_two_numbers(number1, number2)
print("The sum of", number1, "and", number2, "is", result)