Spaces:
Build error
Build error
Fixed API configuration for Gradio 5.x compatibility: Changed endpoint from generate to predict and updated payload format
76a0147 | import requests | |
| import json | |
| import os | |
| # No token needed for public API access | |
| print("Testing public API access...") | |
| # Base URL for the Hugging Face Space | |
| BASE_URL = "https://ebenezermerd-lastdance.hf.space" | |
| # API endpoint for predict functionality - Updated for Gradio 5.x | |
| API_URL = f"{BASE_URL}/api/predict" # Changed from /api/generate to /api/predict | |
| print(f"\nTesting API endpoint: {API_URL}") | |
| # Standard payload format | |
| payload = { | |
| "data": [ # Wrap parameters in a "data" array for Gradio 5.x | |
| 10, # num_route_samples | |
| 5, # num_feedback_samples | |
| False, # use_sdv | |
| 42, # seed | |
| "json" # format | |
| ] | |
| } | |
| # Only content type header is needed | |
| headers = { | |
| "Content-Type": "application/json" | |
| } | |
| try: | |
| print("\nSending request...") | |
| response = requests.post(API_URL, json=payload, headers=headers, timeout=60) | |
| print(f"Status code: {response.status_code}") | |
| if response.status_code == 200: | |
| print("SUCCESS! API endpoint is working!") | |
| result = response.json() | |
| print("Response structure:", result.keys() if isinstance(result, dict) else "Not a dictionary") | |
| # For Gradio 5.x, results are typically wrapped in a "data" field | |
| data = result.get("data", result) | |
| # Extract data from result | |
| if isinstance(data, dict) and "routes" in data: | |
| routes = data["routes"] | |
| print(f"\nGenerated {len(routes)} routes") | |
| print(f"First route example:") | |
| print(json.dumps(routes[0], indent=2)[:300] + "...") | |
| if isinstance(data, dict) and "feedback" in data: | |
| feedback = data["feedback"] | |
| print(f"\nGenerated {len(feedback)} feedback items") | |
| print(f"First feedback example:") | |
| print(json.dumps(feedback[0], indent=2)[:300] + "...") | |
| else: | |
| print("\nUnexpected response format:") | |
| print(json.dumps(data, indent=2)[:500] if isinstance(data, (dict, list)) else str(data)[:500]) | |
| else: | |
| print(f"Error response: {response.text[:500]}") | |
| except Exception as e: | |
| print(f"Error: {str(e)}") | |
| # Try the example from the README - updated for Gradio 5.x format | |
| print("\n\nTrying README example...") | |
| payload_readme = { | |
| "data": [ | |
| 5, # num_route_samples | |
| 3, # num_feedback_samples | |
| True, # use_sdv | |
| 42, # seed | |
| "json" # format | |
| ] | |
| } | |
| try: | |
| response_readme = requests.post(API_URL, json=payload_readme, headers=headers, timeout=60) | |
| print(f"Status code: {response_readme.status_code}") | |
| if response_readme.status_code == 200: | |
| print("README example SUCCESS!") | |
| result = response_readme.json() | |
| data = result.get("data", result) | |
| print(f"Data keys: {data.keys() if isinstance(data, dict) else 'Not a dictionary'}") | |
| else: | |
| print(f"README example ERROR: {response_readme.text[:500]}") | |
| except Exception as e: | |
| print(f"README example ERROR: {str(e)}") | |
| # Also test alternative endpoint formats in case the app uses a different configuration | |
| alternative_endpoints = [ | |
| f"{BASE_URL}/run/predict", | |
| f"{BASE_URL}/run/api", | |
| f"{BASE_URL}/api/generate" # Original endpoint in case it still works | |
| ] | |
| for endpoint in alternative_endpoints: | |
| print(f"\nTrying alternative endpoint: {endpoint}") | |
| try: | |
| response = requests.post(endpoint, json=payload, headers=headers, timeout=30) | |
| print(f"Status code: {response.status_code}") | |
| if response.status_code == 200: | |
| print(f"SUCCESS with {endpoint}!") | |
| break | |
| else: | |
| print(f"Error or not found") | |
| except Exception as e: | |
| print(f"Error: {str(e)}") |