#!/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.")