Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| Easy launcher for the terminal chatbot | |
| """ | |
| import subprocess | |
| import sys | |
| import os | |
| def main(): | |
| print("π€ AI Coding Assistant Terminal Launcher") | |
| print("=" * 50) | |
| # Check if model_server.py exists | |
| if not os.path.exists("model_server.py"): | |
| print("β model_server.py not found!") | |
| print("Make sure all files are in the same directory.") | |
| sys.exit(1) | |
| # Check if terminal_chatbot.py exists | |
| if not os.path.exists("terminal_chatbot.py"): | |
| print("β terminal_chatbot.py not found!") | |
| print("Make sure all files are in the same directory.") | |
| sys.exit(1) | |
| print("π Files found:") | |
| print(" β model_server.py") | |
| print(" β terminal_chatbot.py") | |
| print(" β models.py") | |
| print(" β utils.py") | |
| print() | |
| # Ask user what they want to run | |
| print("What would you like to run?") | |
| print("1. Start model server (required for chatbot)") | |
| print("2. Start terminal chatbot (requires running server)") | |
| print("3. Start both (server in background, then chatbot)") | |
| try: | |
| choice = input("\nEnter your choice (1-3): ").strip() | |
| except KeyboardInterrupt: | |
| print("\nπ Goodbye!") | |
| sys.exit(0) | |
| if choice == "1": | |
| print("\nπ Starting model server...") | |
| print("π‘ Server will run on http://localhost:8000") | |
| print("π‘ Press Ctrl+C to stop") | |
| try: | |
| subprocess.run([sys.executable, "model_server.py"]) | |
| except KeyboardInterrupt: | |
| print("\nπ Server stopped") | |
| elif choice == "2": | |
| print("\nπ€ Starting terminal chatbot...") | |
| print("π‘ Make sure the server is running first!") | |
| print("π‘ If you get connection errors, run option 1 first") | |
| try: | |
| subprocess.run([sys.executable, "terminal_chatbot.py"]) | |
| except KeyboardInterrupt: | |
| print("\nπ Chatbot stopped") | |
| elif choice == "3": | |
| print("\nπ Starting server in background...") | |
| print("π‘ Server will run on http://localhost:8000") | |
| # Start server in background | |
| server_process = subprocess.Popen([sys.executable, "model_server.py"]) | |
| try: | |
| # Wait a bit for server to start | |
| print("β³ Waiting for server to start...") | |
| import time | |
| time.sleep(5) | |
| print("π€ Starting terminal chatbot...") | |
| subprocess.run([sys.executable, "terminal_chatbot.py"]) | |
| except KeyboardInterrupt: | |
| print("\nπ Stopping...") | |
| finally: | |
| # Clean up server process | |
| print("π§Ή Stopping server...") | |
| server_process.terminate() | |
| server_process.wait() | |
| print("β Server stopped") | |
| else: | |
| print("β Invalid choice. Please run again and select 1, 2, or 3.") | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| main() | |
| This creates a complete client-server architecture: | |
| ## π **Key Features:** | |
| ### **Terminal Chatbot (`terminal_chatbot.py`)** | |
| - Beautiful CLI interface with Rich formatting | |
| - Command support (`/help`, `/lang`, `/temp`, `/clear`, etc.) | |
| - Real-time API communication | |
| - Syntax-highlighted code display | |
| - Conversation history management | |
| ### **Model Server (`model_server.py`)** | |
| - FastAPI server hosting the 5B+ parameter model | |
| - RESTful API endpoints for chat and model info | |
| - Health monitoring and status checking | |
| - CORS enabled for web clients | |
| - Background model loading | |
| ### **Updated Gradio App (`updated_app.py`)** | |
| - Works with the API server | |
| - Real-time status monitoring | |
| - Same features as before but via API | |
| ### **Easy Launcher (`run_client.py`)** | |
| - Simple menu-driven interface | |
| - Can start server, client, or both | |
| - Error checking and guidance | |
| ## π **How to Use:** | |
| 1. **Start the server:** | |
| python model_server.py | |
| 2. **Start the terminal chatbot:** | |
| python terminal_chatbot.py | |
| 3. **Or use the easy launcher:** | |
| python run_client.py | |
| 4. **For the Gradio web interface:** | |
| python updated_app.py | |
| ## π **API Endpoints:** | |
| - `GET /health` - Check server status | |
| - `GET /model/info` - Get model information | |
| - `POST /api/chat` - Send chat messages | |
| - `POST /api/validate-code` - Validate code syntax | |
| - `GET /api/languages` - Get supported languages | |
| The terminal chatbot provides a professional CLI experience with syntax highlighting, command support, and real-time API communication! |