""" Wrdler - Gradio Application Entry Point A vocabulary puzzle game with an 8x6 grid and 6 hidden words. This is the Gradio version, running alongside the Streamlit app. Usage: python gradio_app.py # or gradio gradio_app.py """ import os import tempfile from pathlib import Path import gradio as gr from wrdler.gradio_ui import create_app # Import word_loader_ai to register MCP functions # This must happen before creating the app try: from wrdler import word_loader_ai print("? word_loader_ai module loaded (MCP functions may be registered)") except Exception as e: print(f"?? Could not load word_loader_ai: {e}") # Get the project root directory (where this file is located) PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) # Set the current working directory to project root # This ensures file paths are resolved correctly os.chdir(PROJECT_ROOT) print(f"Working Directory: {os.getcwd()}") print(f"Project Root: {PROJECT_ROOT}") # Create the Gradio app demo = create_app() if __name__ == "__main__": # Configure paths for static assets favicon_path = os.path.join(PROJECT_ROOT, "static", "favicon.ico") # Get Gradio's temp directory gradio_temp_dir = Path(tempfile.gettempdir()) / "gradio" # Verify audio directory exists audio_dir = os.path.join(PROJECT_ROOT, "wrdler", "assets", "audio") print(f"Audio directory exists: {os.path.exists(audio_dir)}") if os.path.exists(audio_dir): # List audio files for debugging music_dir = os.path.join(audio_dir, "music") effects_dir = os.path.join(audio_dir, "effects") if os.path.exists(music_dir): music_files = [f for f in os.listdir(music_dir) if f.endswith('.mp3')] print(f"Music files found: {music_files}") if os.path.exists(effects_dir): effect_files = [f for f in os.listdir(effects_dir) if f.endswith('.mp3')] print(f"Effect files found: {effect_files}") # Check MCP server status use_hf_words = os.getenv("USE_HF_WORDS", "false").lower() == "true" if not use_hf_words: print("\n" + "="*70) print("?? MCP SERVER ENABLED (Local Mode)") print("="*70) print("MCP tools available:") print(" - generate_ai_words: Generate AI vocabulary words for topics") print("\nTo use MCP tools, connect your MCP client to this Gradio app.") print("See: https://www.gradio.app/guides/building-mcp-server-with-gradio") print("="*70 + "\n") else: print("\n?? MCP server disabled (USE_HF_WORDS=true, running in remote mode)") # Launch configuration launch_kwargs = { "server_name": "0.0.0.0", "server_port": 7860, "share": False, "show_error": True, # Enable MCP server in local mode "mcp_server": not use_hf_words, # Gradio's allowed_paths should include: # 1. Project root (for any relative paths) # 2. System temp directory (where Gradio caches files) "allowed_paths": [ PROJECT_ROOT, str(gradio_temp_dir), tempfile.gettempdir(), ], } # Add favicon if it exists if os.path.exists(favicon_path): launch_kwargs["favicon_path"] = favicon_path print(f"\nLaunching Gradio app...") print(f"Allowed paths:") for path in launch_kwargs['allowed_paths']: print(f" - {path}") print(f"Server URL: http://localhost:7860") if launch_kwargs["mcp_server"]: print(f"MCP Server: ENABLED") demo.launch(**launch_kwargs)