This repository contains the code to build a Generative AI-powered chatbot using Python. The project includes a Flask backend to interact with the OpenAI API and a Streamlit frontend to provide a user-friendly interface for users to communicate with the chatbot.
- AI-Powered Chatbot: Uses OpenAI's GPT model to generate intelligent and contextual responses.
- Flask Backend: Handles API requests and integrates with OpenAI.
- Streamlit Frontend: Provides a clean and interactive web interface for users.
- Easy Setup: Minimal dependencies, with clear instructions to get started quickly.
- Installation
- Usage
- Project Structure
- Workflow
- Troubleshooting
- Future Improvements
- Python 3.8 or later
- OpenAI API Key (Get one here)
- Clone the repository:
git clone https://github.com/assadchaudhry/generative-ai-chatbot.git cd generative-ai-chatbot
- Set up a virtual environment:
python -m venv chatbot_env source chatbot_env/bin/activate # On Windows: chatbot_env\Scripts\activate
- Install the required dependencies:
pip install -r requirements.txt
- Set your OpenAI API Key:
- Open
chatbot_backend.py
and replace"your-openai-api-key"
with your actual API key.
- Open
- Start the Flask backend:
python chatbot_backend.py
- The backend API will run at
http://localhost:5000/chat
.
- Launch the Streamlit frontend:
streamlit run chatbot_frontend.py
- Access the app in your browser at
http://localhost:8501
.
|-- chatbot_backend.py # Backend API with Flask
|-- chatbot_frontend.py # Frontend interface with Streamlit
|-- requirements.txt # List of dependencies
- User Input: The user enters a message in the Streamlit frontend.
- Backend Processing: The frontend sends the message to the Flask API, which forwards it to the OpenAI API.
- AI Response: OpenAI generates a response, which is sent back to the frontend.
- Display: The frontend displays the AI's response to the user.
- Invalid API Key: Ensure your OpenAI API key is set correctly in
chatbot_backend.py
. - Connection Errors: Verify that the backend is running at
http://localhost:5000
. - Streamlit Errors: Ensure Streamlit is installed and updated.
- Use logs to trace issues in both the backend and frontend.
- Test API endpoints using tools like Postman or curl.
- Add user authentication for secured access.
- Enhance the chatbot with memory to handle longer conversations.
- Deploy the app to a cloud platform for public use.
- Improve the UI/UX of the frontend with additional features.
Contributions are welcome! Feel free to submit issues or pull requests to improve this project.
This project is licensed under the MIT License. See the LICENSE file for more details.