app-cmkofd-64 / run_client.py
AiCoderv2's picture
Update Gradio app with multiple files
6a6c658 verified
#!/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!