|
|
|
|
|
""" |
|
|
Test script for the Tarot Space API |
|
|
""" |
|
|
|
|
|
import requests |
|
|
import json |
|
|
|
|
|
def test_tarot_api(space_url, card_name="The Fool", orientation="upright", question=""): |
|
|
""" |
|
|
Test the tarot API endpoint |
|
|
""" |
|
|
api_url = f"{space_url}/api/predict" |
|
|
|
|
|
payload = { |
|
|
"data": [card_name, orientation, question] |
|
|
} |
|
|
|
|
|
try: |
|
|
response = requests.post(api_url, json=payload) |
|
|
response.raise_for_status() |
|
|
|
|
|
result = response.json() |
|
|
return result |
|
|
|
|
|
except requests.exceptions.RequestException as e: |
|
|
return {"error": f"API request failed: {str(e)}"} |
|
|
|
|
|
def main(): |
|
|
|
|
|
space_url = "https://your-username-tarot-space.hf.space" |
|
|
|
|
|
print("🔮 Testing Tarot API...") |
|
|
print(f"Space URL: {space_url}") |
|
|
print("-" * 50) |
|
|
|
|
|
|
|
|
test_cases = [ |
|
|
{ |
|
|
"card_name": "The Fool", |
|
|
"orientation": "upright", |
|
|
"question": "What should I focus on in my career?" |
|
|
}, |
|
|
{ |
|
|
"card_name": "The Magician", |
|
|
"orientation": "upright", |
|
|
"question": "" |
|
|
}, |
|
|
{ |
|
|
"card_name": "The Lovers", |
|
|
"orientation": "reversed", |
|
|
"question": "What does this mean for my relationship?" |
|
|
} |
|
|
] |
|
|
|
|
|
for i, test_case in enumerate(test_cases, 1): |
|
|
print(f"\nTest {i}:") |
|
|
print(f"Card: {test_case['card_name']}") |
|
|
print(f"Orientation: {test_case['orientation']}") |
|
|
print(f"Question: {test_case['question'] or 'None'}") |
|
|
|
|
|
result = test_tarot_api( |
|
|
space_url, |
|
|
test_case['card_name'], |
|
|
test_case['orientation'], |
|
|
test_case['question'] |
|
|
) |
|
|
|
|
|
if 'error' in result: |
|
|
print(f"❌ Error: {result['error']}") |
|
|
else: |
|
|
print(f"✅ Response: {result.get('data', 'No data returned')}") |
|
|
|
|
|
print("-" * 30) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
|