File size: 1,406 Bytes
a5a6a2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import time
import sys
import os

API_URL = "http://localhost:8000"
IMAGE_PATH = "/home/codernotme/.gemini/antigravity/brain/fd9634fe-740d-41a0-9d95-4bd5df08a975/test_face_1770615920629.png" # Updated path

def wait_for_server():
    print("Waiting for server...")
    for i in range(30):
        try:
            response = requests.get(f"{API_URL}/health")
            if response.status_code == 200:
                print("Server is ready!")
                return True
        except requests.exceptions.ConnectionError:
            pass
        time.sleep(2)
        print(".", end="", flush=True)
    print("\nServer timed out.")
    return False

def test_recommendation():
    if not os.path.exists(IMAGE_PATH):
        print(f"Test image not found at {IMAGE_PATH}")
        return

    print(f"Testing recommendation with {IMAGE_PATH}...")
    try:
        with open(IMAGE_PATH, "rb") as f:
            files = {"file": f}
            response = requests.post(f"{API_URL}/recommend", files=files)
        
        if response.status_code == 200:
            print("Success!")
            print(response.json())
        else:
            print(f"Failed: {response.status_code}")
            print(response.text)
    except Exception as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    if wait_for_server():
        test_recommendation()
    else:
        sys.exit(1)