A simple AI ChatBot built with FastAPI as the backend and Streamlit as the frontend. This project uses Python 3.11 and integrates with Groq, OpenAI, and Tavily APIs. Sensitive API keys are stored securely in a .env file.
- Backend: FastAPI application deployed on Render.
- Frontend: Streamlit app hosted on Streamlit Community Cloud.
- API Keys: Managed using a
.envfile (not tracked in source control).
- Chat Endpoint: FastAPI handles chat requests at the
/chatendpoint. - Interactive Frontend: Streamlit UI for chatting with the AI agent.
- API Integrations: Supports Groq, OpenAI, and Tavily APIs.
- Secure Configuration: All API keys and secrets are stored in a
.envfile.
Try out the AI ChatBot frontend hosted on Streamlit Community Cloud:
-
Clone the Repository:
git clone https://github.com/your-username/AI_ChatBot.git cd AI_ChatBot -
Create and Activate a Virtual Environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies:
pip install -r requirements.txt
-
Configure Environment Variables:
Create a
.envfile in the project root and add your API keys:GROQ_API_KEY="your_groq_api_key" OPENAI_API_KEY="your_openai_api_key" TAVILY_API_KEY="your_tavily_api_key"
-
Run the Backend Locally:
Navigate to the folder containing
backend.py(if needed, adjust your commands according to your project layout):uvicorn backend:app --host 127.0.0.1 --port 9999
-
Run the Frontend Locally:
In the project root, run:
streamlit run frontend.py
Make sure the
API_URLin yourfrontend.pypoints to your local backend (e.g.,http://127.0.0.1:9999/chat).
-
Repository Setup:
- Push your project to GitHub.
- In Render’s dashboard, create a new web service.
- Set the Root Directory to the folder that contains your
backend.py(if needed).
-
Configure Build & Start Commands:
- Build Command:
pip install -r requirements.txt
- Start Command:
uvicorn backend:app --host 0.0.0.0 --port $PORT
- Build Command:
-
Environment Variables:
- Add your API keys in the Render dashboard using the environment variable settings (or upload them via your
.envfile using Render's secret files feature).
- Add your API keys in the Render dashboard using the environment variable settings (or upload them via your
-
Deploy:
Once configured, trigger a deploy. Your backend will be available at a public URL (e.g.,
https://your-backend.onrender.com/chat).
-
Push Your Code to GitHub:
Ensure that the repository (or a branch) containingfrontend.pyis available. -
Create a New App on Streamlit Cloud:
- Connect your GitHub repository.
- Set up any necessary secrets using Streamlit's secrets management (if needed).
-
Update API URL:
- In
frontend.py, updateAPI_URLto point to your deployed backend URL (e.g.,https://your-backend.onrender.com/chat).
- In
-
Deploy:
Your Streamlit app will automatically build and deploy on the community cloud.