This project is a web-based AI chatbot built using Flask and GPT-2, with a simple HTML frontend for user interaction. The chatbot processes user input, generates responses using a pretrained GPT-2 model, and communicates with the backend via AJAX.
- Real-Time Chat: Interactive chat interface for users.
- GPT-2 Responses: Generates human-like responses using GPT-2.
- Flask Backend: Handles API requests and integrates with the chatbot model.
- AJAX Communication: Sends and receives messages asynchronously.
-
Clone the repository:
git clone https://github.com/your-repo/ai-chatbot.git cd ai-chatbot -
Install dependencies:
pip install Flask transformers nltk
-
Download NLTK resources:
import nltk nltk.download('punkt') nltk.download('stopwords')
-
Run the Flask server:
python app.py
-
Open the browser and navigate to:
http://127.0.0.1:5000/
app.py: Flask backend handling requests and generating responses.index.html: Frontend HTML for the chat interface.static/: Directory for static files (CSS, JS).
- Request: JSON payload with a
messagefield. - Response: JSON object containing the bot's response.
- Example:
curl -X POST http://127.0.0.1:5000/chat -H "Content-Type: application/json" -d '{"message": "Hello"}'
- Flask: For the web server and handling HTTP requests.
- transformers: For GPT-2 model usage.
- NLTK: For preprocessing input text.
- SQLite: For storing conversation history (in-memory database).
Install dependencies with:
pip install Flask transformers nltk- Model: The GPT-2 model is loaded from Hugging Face.
- Database: Uses an in-memory SQLite database.