Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Simple test script to verify the FastAPI recipe service is working | |
| """ | |
| import requests | |
| import json | |
| # Test the API endpoints | |
| BASE_URL = "https://nutrientartcd-recipe-ai-fastapi.hf.space" # Update this to your actual URL | |
| def test_health_check(): | |
| """Test the health check endpoint""" | |
| try: | |
| response = requests.get(f"{BASE_URL}/") | |
| print("π₯ Health Check:") | |
| print(f"Status: {response.status_code}") | |
| if response.status_code == 200: | |
| data = response.json() | |
| print(f"Recipe count: {data.get('recipe_count', 'N/A')}") | |
| print(f"Recipes loaded: {data.get('recipes_loaded', False)}") | |
| return True | |
| else: | |
| print(f"Error: {response.text}") | |
| return False | |
| except Exception as e: | |
| print(f"β Health check failed: {e}") | |
| return False | |
| def test_recipe_suggestions(): | |
| """Test the recipe suggestions endpoint""" | |
| try: | |
| # Test the exact scenario from the screenshot | |
| payload = { | |
| "ingredients": "something chocolate for dessert", | |
| "preferences": "", | |
| "max_minutes": 30 | |
| } | |
| response = requests.post( | |
| f"{BASE_URL}/api/recipe-suggestions", | |
| json=payload, | |
| headers={"Content-Type": "application/json"} | |
| ) | |
| print("\nπ« Chocolate Dessert Test:") | |
| print(f"Status: {response.status_code}") | |
| if response.status_code == 200: | |
| data = response.json() | |
| print(f"Status: {data.get('status')}") | |
| recipes = data.get('recommendations', []) | |
| print(f"Found {len(recipes)} recipes") | |
| # Check if we got dessert recipes with chocolate | |
| dessert_count = 0 | |
| chocolate_count = 0 | |
| for i, recipe in enumerate(recipes): | |
| name = recipe.get('name', '').lower() | |
| ingredients = ' '.join(recipe.get('ingredients', [])).lower() | |
| print(f"\nRecipe {i+1}:") | |
| print(f" ID: {recipe.get('id')}") | |
| print(f" Name: {recipe.get('name')}") | |
| print(f" Minutes: {recipe.get('minutes')}") | |
| # Check for dessert indicators | |
| if any(word in name for word in ['cake', 'cookie', 'brownie', 'dessert', 'sweet']): | |
| dessert_count += 1 | |
| print(f" β DESSERT DETECTED") | |
| # Check for chocolate | |
| if 'chocolate' in name or 'chocolate' in ingredients: | |
| chocolate_count += 1 | |
| print(f" π« CHOCOLATE DETECTED") | |
| if not any(word in name for word in ['cake', 'cookie', 'brownie', 'dessert', 'sweet']): | |
| print(f" β NOT A DESSERT") | |
| print(f"\nπ Results:") | |
| print(f" Dessert recipes: {dessert_count}/{len(recipes)}") | |
| print(f" Chocolate recipes: {chocolate_count}/{len(recipes)}") | |
| success = dessert_count > 0 or chocolate_count > 0 | |
| if success: | |
| print("β SUCCESS: Found relevant dessert/chocolate recipes!") | |
| else: | |
| print("β FAILED: No dessert or chocolate recipes found") | |
| return success | |
| else: | |
| print(f"Error: {response.text}") | |
| return False | |
| except Exception as e: | |
| print(f"β Recipe suggestions failed: {e}") | |
| return False | |
| if __name__ == "__main__": | |
| print("π§ͺ Testing FastAPI Recipe Service") | |
| print(f"Base URL: {BASE_URL}") | |
| print("-" * 50) | |
| health_ok = test_health_check() | |
| if health_ok: | |
| recipes_ok = test_recipe_suggestions() | |
| if recipes_ok: | |
| print("\nβ All tests passed! The API is working correctly.") | |
| else: | |
| print("\nβ Recipe suggestions test failed.") | |
| else: | |
| print("\nβ Health check failed - service may not be running.") |