#!/usr/bin/env python3 """ GUI Launcher for LLM Business Chatbot This script launches the Gradio web interface for the chatbot application. It provides a web-based GUI that wraps around the existing CLI chatbot without modifying any of the original code. Usage: python run_gui.py # Launch with default settings python run_gui.py --port 8080 # Launch on custom port python run_gui.py --share # Create public sharing link python run_gui.py --debug # Enable debug mode """ import spacy import subprocess import importlib.util def is_model_installed(model_name): return importlib.util.find_spec(model_name) is not None model = "en_core_web_sm" if not is_model_installed(model): subprocess.run(["python", "-m", "spacy", "download", model]) import sys import os import argparse from pathlib import Path # Add gui directory to path gui_dir = Path(__file__).parent / "gui" sys.path.append(str(gui_dir)) def main(): """Main function to parse arguments and launch the GUI.""" parser = argparse.ArgumentParser( description="Launch Gradio GUI for LLM Business Chatbot", formatter_class=argparse.RawDescriptionHelpFormatter, epilog=""" Examples: python run_gui.py # Default: localhost:7860 python run_gui.py --port 8080 # Custom port python run_gui.py --share # Public sharing link python run_gui.py --host 0.0.0.0 # Accept external connections python run_gui.py --debug # Enable debug mode """ ) parser.add_argument( "--host", default="0.0.0.0", help="Host address to bind to (default: 0.0.0.0)" ) parser.add_argument( "--port", type=int, default=7860, help="Port number to run the server on (default: 7860)" ) parser.add_argument( "--share", action="store_true", help="Create a public sharing link via Gradio" ) parser.add_argument( "--debug", action="store_true", help="Enable debug mode" ) parser.add_argument( "--quiet", action="store_true", help="Suppress startup messages" ) args = parser.parse_args() # Print startup banner if not args.quiet: print("=" * 70) print("šŸ¤– LLM Business Chatbot - Gradio GUI") print("=" * 70) print(f"🌐 Starting web interface...") print(f"šŸ“ Host: {args.host}") print(f"šŸ”Œ Port: {args.port}") print(f"šŸ”— Share: {'Yes' if args.share else 'No'}") print(f"šŸ› Debug: {'Yes' if args.debug else 'No'}") print("-" * 70) try: # Import and launch the Gradio interface from gradio_interface import GradioInterface gui = GradioInterface() gui.launch( server_name=args.host, server_port=args.port, share=args.share, debug=args.debug, quiet=args.quiet, show_error=True ) except ImportError as e: print(f"āŒ Error: Missing dependencies. Please install requirements:") print(f" pip install -r requirements.txt") print(f" Error details: {e}") sys.exit(1) except KeyboardInterrupt: if not args.quiet: print("\nšŸ‘‹ Shutting down Gradio interface...") sys.exit(0) except Exception as e: print(f"āŒ Error launching GUI: {e}") if args.debug: import traceback traceback.print_exc() sys.exit(1) if __name__ == "__main__": main()