Repository navigation
Expand file tree
/
Copy pathtest_api.py
More file actions
56 lines (45 loc) · 1.72 KB
/
Copy pathtest_api.py
File metadata and controls
56 lines (45 loc) · 1.72 KB
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
# test_api.py
# This script tests our API by uploading a test image
import requests
from PIL import Image
import io
# Create a test image (green square representing a plant leaf)
print("📸 Creating test plant image...")
test_image = Image.new('RGB', (400, 400), color='green')
# Save to bytes (in memory)
img_byte_arr = io.BytesIO()
test_image.save(img_byte_arr, format='JPEG')
img_byte_arr.seek(0)
print("🚀 Sending image to API for analysis...")
# Send to our API
try:
response = requests.post(
'http://localhost:5000/api/analyze',
files={'image': ('test_plant.jpg', img_byte_arr, 'image/jpeg')}
)
# Print results
if response.status_code == 200:
result = response.json()
print("\n" + "="*60)
print("✅ SUCCESS! Analysis complete!")
print("="*60)
data = result['data']
print(f"\n🌱 Plant: {data['plantName']}")
print(f"🏥 Health Status: {data['healthStatus']}")
if data['diseaseDetected']:
print(f"🦠 Disease: {data['diseaseName']}")
print(f"📊 Confidence: {data['confidence']}%")
print(f"⚠️ Severity: {data['severity']}")
print(f"\n📝 Description:\n{data['description']}")
print(f"\n💊 Solutions:")
for i, solution in enumerate(data['solutions'], 1):
print(f" {i}. {solution}")
else:
print("✅ Plant is healthy!")
else:
print(f"❌ Error: {response.status_code}")
print(response.text)
except Exception as e:
print(f"❌ Error: {e}")
print("\n💡 Make sure the server is running!")
print(" Run 'python app.py' in another terminal")