Skip to content

A GPT-powered chatbot that handles general chat, code generation, and math queries, integrated with Firebase Firestore to store/retrieve chat history. It features a Streamlit web interface for seamless interaction, displaying responses with typing effects, including Python code snippets.

Notifications You must be signed in to change notification settings

Saaarthak0102/GEN-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Features

  • 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.

Prerequisites

Before running this project, make sure you have the following:

Setup

1. Clone the repository:

git clone https://github.com/yourusername/your-repo.git
cd your-repo

2. Create a virtual environment:

python -m venv venv
source venv/bin/activate  # For Linux/macOS
venv\Scripts\activate     # For Windows

3. Install dependencies:

pip install -r requirements.txt

4. Set up Firebase and Google API Key:

Firebase Setup

  1. Create a Firebase project in the Firebase Console.
  2. Enable Firestore as your database.
  3. 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.

Google API Key

  1. Go to Google's AI Model API and create a new API key.
  2. Copy the API key and add it to the .env file.

5. Set up environment variables:

  • 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

6. Running the App

  1. Start the Streamlit app:

    streamlit run main.py
  2. This will open a web interface where you can start chatting with the AI bot.

Project Structure

  • 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.

Usage

Start Chatting

  • 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.

Chatbot Interaction

  • 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.

Key Components

Backend (backend.py)

  • 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.).

Frontend (main.py)

  • 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.

Example Chatbot Interaction

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)

About

A GPT-powered chatbot that handles general chat, code generation, and math queries, integrated with Firebase Firestore to store/retrieve chat history. It features a Streamlit web interface for seamless interaction, displaying responses with typing effects, including Python code snippets.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages