Spaces:
Running
Running
File size: 3,049 Bytes
8899cc8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
#!/usr/bin/env python
"""
Quick test script to verify MCP integration is working.
This script:
1. Checks if Gradio MCP dependencies are installed
2. Verifies the MCP function registration
3. Tests the generate_ai_words wrapper
Usage:
python test_mcp.py
"""
import os
import sys
def test_gradio_mcp():
"""Test Gradio MCP support."""
print("="*70)
print("Testing Gradio MCP Integration")
print("="*70)
# Test 1: Check Gradio installation
print("\n1. Checking Gradio installation...")
try:
import gradio as gr
print(f" ? Gradio version: {gr.__version__}")
except ImportError as e:
print(f" ? Gradio not installed: {e}")
return False
# Test 2: Check MCP dependencies
print("\n2. Checking MCP dependencies...")
try:
import mcp
print(f" ? MCP package installed")
except ImportError:
print(f" ?? MCP package not installed")
print(f" Install with: pip install 'gradio[mcp]'")
# Not critical - continue anyway
# Test 3: Check word_loader_ai module
print("\n3. Checking word_loader_ai module...")
try:
from wrdler import word_loader_ai
print(f" ? word_loader_ai module loaded")
# Check if MCP function exists
if hasattr(word_loader_ai, 'mcp_generate_ai_words'):
print(f" ? MCP function 'mcp_generate_ai_words' registered")
else:
print(f" ?? MCP function not registered (may be disabled by USE_HF_WORDS flag)")
except ImportError as e:
print(f" ? Failed to load word_loader_ai: {e}")
return False
# Test 4: Check environment variables
print("\n4. Checking environment configuration...")
use_hf_words = os.getenv("USE_HF_WORDS", "false").lower() == "true"
print(f" USE_HF_WORDS: {use_hf_words}")
if use_hf_words:
print(f" ?? MCP server will be DISABLED (remote mode)")
else:
print(f" ? MCP server will be ENABLED (local mode)")
# Test 5: Verify function can be called
print("\n5. Testing MCP function wrapper...")
try:
if hasattr(word_loader_ai, 'mcp_generate_ai_words'):
print(f" ?? Function callable: mcp_generate_ai_words")
print(f" ?? Note: Full test requires AI model (skipping actual generation)")
else:
print(f" ?? Function not available (USE_HF_WORDS=true or Gradio not available)")
except Exception as e:
print(f" ? Error testing function: {e}")
print("\n" + "="*70)
print("MCP Integration Test Complete")
print("="*70)
print("\nTo enable MCP server:")
print(" 1. Set USE_HF_WORDS=false in your environment")
print(" 2. Run: python gradio_app.py")
print(" 3. Connect your MCP client to http://localhost:7860")
print("\nFor detailed setup, see: docs/MCP_INTEGRATION.md")
return True
if __name__ == "__main__":
success = test_gradio_mcp()
sys.exit(0 if success else 1)
|