Spaces:
Sleeping
Sleeping
File size: 1,465 Bytes
bbd5f9c | 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 | #!/usr/bin/env python3
import subprocess
import time
import requests
import json
# Start the server in the background
print("Starting server...")
server_process = subprocess.Popen(
["python3", "start.py"],
env={"PORT": "8005"},
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
# Wait for server to start
time.sleep(8)
try:
# Test health endpoint first
response = requests.get("http://localhost:8005/health", timeout=10)
print(f"Health check: {response.status_code}")
health_data = response.json()
print(f"Model loaded: {health_data.get('model_loaded')}")
# Test prediction endpoint with sample data
prediction_data = {
"year": 2024,
"state": "Punjab",
"crop": "Rice",
"season": "Kharif",
"area": 10.0,
"production": 25.0,
"rainfall": 1200,
"fertilizer": 75,
"pesticide": 8
}
response = requests.post(
"http://localhost:8005/predict",
json=prediction_data,
timeout=10
)
print(f"Prediction status: {response.status_code}")
if response.status_code == 200:
print("✅ Prediction successful!")
print(response.json())
else:
print("❌ Prediction failed:")
print(response.text)
except Exception as e:
print(f"Error testing: {e}")
finally:
# Stop the server
server_process.terminate()
server_process.wait()
print("Server stopped")
|