Spaces:
Sleeping
Sleeping
File size: 2,310 Bytes
c8df794 |
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 |
"""
Simple API test script
"""
import requests
import json
def test_endpoints():
"""Test basic API endpoints"""
base_url = "http://localhost:8000"
print("🧪 Testing API Endpoints...")
print("=" * 40)
# Test health
print("1. Testing /health...")
try:
response = requests.get(f"{base_url}/health", timeout=10)
print(f" Status: {response.status_code}")
print(f" Response: {response.json()}")
except Exception as e:
print(f" Error: {e}")
print()
# Test classes
print("2. Testing /classes...")
try:
response = requests.get(f"{base_url}/classes", timeout=10)
print(f" Status: {response.status_code}")
data = response.json()
print(f" Classes: {len(data['classes'])} total")
except Exception as e:
print(f" Error: {e}")
print()
# Test model info
print("3. Testing /model_info...")
try:
response = requests.get(f"{base_url}/model_info", timeout=10)
print(f" Status: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f" Model: {data['model_name']}")
print(f" Device: {data['device']}")
else:
print(f" Response: {response.text}")
except Exception as e:
print(f" Error: {e}")
print()
# Test prediction (if test image exists)
print("4. Testing /predict...")
try:
import os
if os.path.exists("test_leaf_sample.jpg"):
with open("test_leaf_sample.jpg", "rb") as f:
files = {"file": ("test.jpg", f, "image/jpeg")}
response = requests.post(f"{base_url}/predict", files=files, timeout=30)
print(f" Status: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f" Prediction: {data.get('predicted_class', 'N/A')}")
print(f" Confidence: {data.get('confidence', 'N/A'):.2%}")
else:
print(f" Error: {response.text}")
else:
print(" Test image not found")
except Exception as e:
print(f" Error: {e}")
if __name__ == "__main__":
test_endpoints()
|