tarot / test_api.py
oleh.rostovtsev
Add complete tarot reading app with AI model integration
2fbd0f4
#!/usr/bin/env python3
"""
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():
# Replace with your actual Space URL
space_url = "https://your-username-tarot-space.hf.space"
print("🔮 Testing Tarot API...")
print(f"Space URL: {space_url}")
print("-" * 50)
# Test cases
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()