File size: 4,131 Bytes
0a28346
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cb4c2f7
0a28346
cb4c2f7
 
0a28346
 
 
 
 
 
 
 
 
cb4c2f7
0a28346
 
 
 
 
 
 
 
cb4c2f7
 
 
 
 
 
 
 
0a28346
 
 
 
cb4c2f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a28346
cb4c2f7
0a28346
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/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.")