-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_api.py
More file actions
59 lines (48 loc) · 1.71 KB
/
Copy pathrun_api.py
File metadata and controls
59 lines (48 loc) · 1.71 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
57
58
"""
FastAPI Server Startup Script
Run this to start the FastAPI server
"""
import os
import sys
from pathlib import Path
# Add src to path
sys.path.insert(0, str(Path(__file__).parent))
from src.deployment import create_app
from src.models import PhasePredictor
from src.anomaly import AnomalyDetector
import uvicorn
def main():
"""Start the FastAPI server."""
print("=" * 60)
print("FERMENTATION GAS INTELLIGENCE SYSTEM - FASTAPI SERVER")
print("=" * 60)
# Load models
print("\nLoading models...")
predictor = PhasePredictor()
if os.path.exists('models/phase_predictor.pkl'):
predictor.load('models/phase_predictor.pkl')
print("✓ Phase predictor model loaded")
else:
print("⚠ Warning: Model not found. Train the model first using main.py")
detector = AnomalyDetector()
print("✓ Anomaly detector initialized")
# Create FastAPI app
app = create_app(predictor, detector)
print("\n" + "=" * 60)
print("API Server Starting...")
print("=" * 60)
print("\nAvailable endpoints:")
print(" GET /health - Health check")
print(" POST /predict - Phase forecast (6 hours ahead)")
print(" POST /detect_anomalies - Detect anomalies")
print(" POST /batch_summary - Generate batch summary")
print("\n📚 Interactive API Documentation:")
print(" Swagger UI: http://localhost:8000/docs")
print(" ReDoc: http://localhost:8000/redoc")
print("\nServer running on: http://localhost:8000")
print("Press CTRL+C to stop")
print("=" * 60 + "\n")
# Run the server
uvicorn.run(app, host="0.0.0.0", port=8000, reload=False)
if __name__ == '__main__':
main()