CoolFace
Apppublic

chaitanyakb181005/spam_classifier

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
test_app.py33 linesDownload Raw Back to root
1import requests2import sys3 4def test_endpoints():5    base_url = "http://127.0.0.1:8000"6    7    print(f"Testing GET {base_url}/ ...")8    try:9        r = requests.get(base_url)10        if r.status_code == 200:11            print("Successfully accessed home page.")12        else:13            print(f"Failed to access home page. Status: {r.status_code}")14    except Exception as e:15        print(f"Error connecting to home page: {e}")16 17    print(f"\nTesting POST {base_url}/predict ...")18    test_data = {"text": "This is a wonderful test for classification."}19    try:20        r = requests.post(f"{base_url}/predict", json=test_data)21        if r.status_code == 200:22            result = r.json()23            print("Successfully received prediction:")24            print(result)25        else:26            print(f"Failed to get prediction. Status: {r.status_code}")27            print(r.text)28    except Exception as e:29        print(f"Error connecting to predict endpoint: {e}")30 31if __name__ == "__main__":32    test_endpoints()33