Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -4,26 +4,10 @@ import numpy as np
|
|
| 4 |
import joblib
|
| 5 |
import random
|
| 6 |
import os
|
| 7 |
-
import threading
|
| 8 |
-
import time
|
| 9 |
from fastapi import FastAPI
|
| 10 |
from fastapi.middleware.cors import CORSMiddleware
|
| 11 |
from pydantic import BaseModel
|
| 12 |
-
from pyngrok import ngrok
|
| 13 |
from contextlib import asynccontextmanager
|
| 14 |
-
import uvicorn
|
| 15 |
-
|
| 16 |
-
# ==========================================
|
| 17 |
-
# 0. CLEANUP & AUTH
|
| 18 |
-
# ==========================================
|
| 19 |
-
print("🧹 Cleaning up old sessions...")
|
| 20 |
-
ngrok.kill()
|
| 21 |
-
os.system("fuser -k 8000/tcp")
|
| 22 |
-
|
| 23 |
-
# Using the token from the second script
|
| 24 |
-
NGROK_TOKEN = "38wFP4o09vV9sgwJUoWM2euBk7J_2WnPVQ4XfT7pT9ndARhwJ"
|
| 25 |
-
ngrok.set_auth_token(NGROK_TOKEN)
|
| 26 |
-
print("🔑 New Ngrok Token Applied.")
|
| 27 |
|
| 28 |
# ==========================================
|
| 29 |
# 1. MODEL ARCHITECTURES
|
|
@@ -217,25 +201,3 @@ def predict_battery(data: BatteryData):
|
|
| 217 |
"temp": round(float(temp_est), 2),
|
| 218 |
"status": status
|
| 219 |
}
|
| 220 |
-
|
| 221 |
-
# ==========================================
|
| 222 |
-
# 5. LAUNCH
|
| 223 |
-
# ==========================================
|
| 224 |
-
def run_server():
|
| 225 |
-
config = uvicorn.Config(app, port=8000, log_level="error")
|
| 226 |
-
server = uvicorn.Server(config)
|
| 227 |
-
server.install_signal_handlers = lambda: None
|
| 228 |
-
server.run()
|
| 229 |
-
|
| 230 |
-
t = threading.Thread(target=run_server)
|
| 231 |
-
t.start()
|
| 232 |
-
|
| 233 |
-
print("⏳ Initializing D.E.C.O.D.E. Unified API...", end="")
|
| 234 |
-
time.sleep(5)
|
| 235 |
-
|
| 236 |
-
try:
|
| 237 |
-
public_url = ngrok.connect(8000).public_url
|
| 238 |
-
print(f"\n🚀 API LIVE: {public_url}")
|
| 239 |
-
print(f"🔗 DOCS: {public_url}/docs")
|
| 240 |
-
except Exception as e:
|
| 241 |
-
print(f"\n❌ Connection Error: {e}")
|
|
|
|
| 4 |
import joblib
|
| 5 |
import random
|
| 6 |
import os
|
|
|
|
|
|
|
| 7 |
from fastapi import FastAPI
|
| 8 |
from fastapi.middleware.cors import CORSMiddleware
|
| 9 |
from pydantic import BaseModel
|
|
|
|
| 10 |
from contextlib import asynccontextmanager
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# ==========================================
|
| 13 |
# 1. MODEL ARCHITECTURES
|
|
|
|
| 201 |
"temp": round(float(temp_est), 2),
|
| 202 |
"status": status
|
| 203 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|