This project is a simple chatbot web application built using the Django framework in Python. It allows users to interact with AI models from OpenAI and Google to get responses to their text and image-based queries. The application features user authentication, chat history, and the ability to send images to the AI for processing.
- User Authentication: Users can register, log in, and log out to secure their chat history.
- Chat Interface: A clean and intuitive interface for real-time interaction with the chatbot.
- Message History: The application stores and displays the user's previous chat history.
- AI Integration: Utilizes both OpenAI and Google AI APIs to provide intelligent responses.
- Text and Image Input: Users can send both text messages and upload images for the AI to process.
- Clear History: Logged-in users have the option to clear their chat history.
- Django: A high-level Python web framework.
- Python: The primary programming language.
- psycopg2: PostgreSQL database adapter for Python.
- OpenAI API: For generating responses based on text input.
- Google Generative AI: For handling both text and image-based queries.
- HTML, CSS, and Bootstrap: For the frontend structure and styling.
- Clone the repository:
git clone <repository_url> cd aichatbot
- Create a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Linux/macOS venv\Scripts\activate.bat # On Windows
- Install dependencies:
This will install the necessary libraries including Django, psycopg2, openai, and google-generativeai.
pip install -r requeriments.txt
- Set up the database:
- Ensure you have PostgreSQL installed and running.
- Create a database for the project.
- Update the database settings in
aichatbot/settings.pywith your database credentials.
- Apply migrations:
python manage.py migrate
- Create a superuser (optional but recommended for admin access):
python manage.py createsuperuser
- Obtain API Keys:
- You will need API keys for OpenAI and Google AI.
- Refer to the respective API documentation for instructions on how to obtain them.
- Set these API keys as environment variables or directly in the
chatbot/openAIAPI.pyandchatbot/googleAPI.pyfiles.
- Run the development server:
python manage.py runserver
- Access the application: Open your web browser and navigate to
http://127.0.0.1:8000/. - Register or Login: New users will need to register before using the chatbot. Existing users can log in with their credentials.
- Start chatting: Once logged in, you will be directed to the chatbot interface where you can type your messages and send them. You can also attach images using the "Attach Image" button. The chatbot's response will appear in the chat window.
- Clear History: You can clear your chat history by clicking on the "Clear History" link.
- Logout: To logout, click on the "Logout" link.
aichatbot/
├── chatbot/
│ ├── admin.py
│ ├── apps.py
│ ├── googleAPI.py # Handles interactions with the Google AI API
│ ├── migrations/
│ │ └── ...
│ ├── models.py # Defines the database models
│ ├── openAIAPI.py # Handles interactions with the OpenAI API
│ ├── tests.py
│ ├── urls.py # Defines URL patterns for the chatbot app
│ └── views.py # Handles the application logic and views
├── templates/
│ ├── base.html # Base HTML template
│ ├── chatbot.html # Chatbot interface template
│ ├── login.html # Login page template
│ └── register.html # Registration page template
├── staticfiles/
│ └── ... # Static files (CSS, JavaScript, etc.)
├── manage.py # Django management script
├── requeriments.txt # Project dependencies
├── settings.py # Django project settings
├── urls.py # Main project URL patterns
├── asgi.py
└── wsgi.py
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them.
- Push your changes to your fork.
- Submit a pull request.
MIT