Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Test script for the Gradio UI functionality | |
| """ | |
| import sys | |
| import os | |
| # Add paths for imports | |
| sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'hf_space')) | |
| sys.path.append(os.path.dirname(os.path.dirname(__file__))) | |
| def test_mcp_client(): | |
| """Test the MCP client integration""" | |
| print("π§ͺ Testing MCP Client Integration...") | |
| try: | |
| from mcp_client import find_best_spots | |
| # Test with a simple location | |
| print(" Testing: MΓ‘laga, Spain") | |
| result = find_best_spots("MΓ‘laga, Spain", max_distance_km=50, top_n=3) | |
| if result.get("ok"): | |
| spots = result.get("results", []) | |
| ai_summary = result.get("ai_summary", "") | |
| print(f" β Found {len(spots)} surf spots") | |
| if ai_summary: | |
| print(f" π€ AI Summary: {ai_summary[:100]}...") | |
| for i, spot in enumerate(spots[:2], 1): | |
| print(f" {i}. {spot['name']} - Score: {spot['score']}/100") | |
| return True | |
| else: | |
| print(f" β Error: {result.get('error')}") | |
| return False | |
| except Exception as e: | |
| print(f" π₯ Exception: {e}") | |
| return False | |
| def test_ui_functions(): | |
| """Test UI formatting functions""" | |
| print("\nπ¨ Testing UI Functions...") | |
| try: | |
| from app import format_spot_results, run_surf_finder | |
| # Test with sample data | |
| sample_spots = [ | |
| { | |
| "name": "Test Spot", | |
| "score": 85.5, | |
| "distance_km": 25.3, | |
| "conditions": {"wave_height": 1.5, "wind_speed": 10}, | |
| "explain": "Good conditions for surfing with moderate waves and favorable wind direction" | |
| } | |
| ] | |
| spots_html, ai_html, reasoning = format_spot_results(sample_spots, "Test AI summary") | |
| if "Test Spot" in spots_html and "85.5" in spots_html: | |
| print(" β Spot formatting works correctly") | |
| else: | |
| print(" β Spot formatting failed") | |
| return False | |
| if "Test AI summary" in ai_html: | |
| print(" β AI summary formatting works") | |
| else: | |
| print(" β AI summary formatting failed") | |
| return False | |
| return True | |
| except Exception as e: | |
| print(f" π₯ Exception: {e}") | |
| return False | |
| def main(): | |
| """Run all tests""" | |
| print("π Testing Surf Spot Finder UI Components") | |
| print("=" * 50) | |
| # Test MCP integration | |
| client_ok = test_mcp_client() | |
| # Test UI functions | |
| ui_ok = test_ui_functions() | |
| print("\n" + "=" * 50) | |
| print("π Test Results:") | |
| print(f" MCP Client: {'β ' if client_ok else 'β'}") | |
| print(f" UI Functions: {'β ' if ui_ok else 'β'}") | |
| if client_ok and ui_ok: | |
| print("\nπ All tests passed! UI is ready for deployment.") | |
| print("π‘ The Gradio app should work correctly on HF Space.") | |
| else: | |
| print("\nβ οΈ Some tests failed. Check the issues above.") | |
| return client_ok and ui_ok | |
| if __name__ == "__main__": | |
| success = main() | |
| sys.exit(0 if success else 1) |