--- title: Basic Chatbot emoji: 💬 colorFrom: blue colorTo: purple sdk: docker app_port: 7860 pinned: false --- # AI Chatbot Flask App Flask service for a fine-tuned GPT-2 conversational chatbot model. ## Setup ### Local Development 1. Install dependencies: ```bash pip install -r requirements.txt ``` 2. Run the app: ```bash python app.py ``` 3. Access the application: - **Web Interface**: http://localhost:7860 (Chat directly in your browser!) - API Info: http://localhost:7860/api - Health check: http://localhost:7860/health ### Docker 1. Build the image: ```bash docker build -t chatbot-api . ``` 2. Run the container: ```bash docker run -p 7860:7860 chatbot-api ``` ## API Endpoints ### Web Interface Visit the root URL to access the interactive chat interface. ### GET `/api` Health check and info ```bash curl http://localhost:7860/api ``` ### GET `/health` Detailed health status ```bash curl http://localhost:7860/health ``` ### POST `/chat` Generate chatbot response Request body: ```json { "user": ["Hello!", "How are you?"], "ai": ["Hi there!"] } ``` Example: ```bash curl -X POST http://localhost:7860/chat \ -H "Content-Type: application/json" \ -d '{"user": ["Hello!"], "ai": []}' ``` Response: ```json { "response": "Hi there! How can I help you today", "device": "cuda:0" } ``` ## Model - **Model**: Fine-tuned GPT-2 - **Location**: `./models/fine-tuned-gpt2` - **Type**: Conversational AI Chatbot - **Port**: 7860 ## Features - CORS enabled for all origins - Automatic GPU detection and usage - Conversation history support (last 7 exchanges) - Clean chat interface - Real-time responses - Message history management - Typing indicators ## Chat Interface The web interface provides: - Real-time chat with the AI - Conversation history - Typing indicators - Clear chat functionality - Responsive design for mobile and desktop