Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,8 +2,9 @@ from fastapi import FastAPI, HTTPException
|
|
2 |
from fastapi.middleware.cors import CORSMiddleware
|
3 |
from pydantic import BaseModel
|
4 |
import numpy as np
|
5 |
-
from huggingface_hub import hf_hub_url, cached_download
|
6 |
import joblib
|
|
|
|
|
7 |
|
8 |
app = FastAPI()
|
9 |
|
@@ -16,17 +17,19 @@ app.add_middleware(
|
|
16 |
allow_headers=["*"],
|
17 |
)
|
18 |
|
19 |
-
|
20 |
-
FILENAME = "npk_needs_model.joblib"
|
21 |
|
22 |
try:
|
23 |
-
|
|
|
|
|
|
|
24 |
print("Model loaded successfully")
|
25 |
except Exception as e:
|
26 |
print(f"Error loading model: {e}")
|
27 |
print(f"Error type: {type(e)}")
|
28 |
print(f"Error details: {str(e)}")
|
29 |
-
raise HTTPException(status_code=500, detail="Unable to
|
30 |
|
31 |
class InputData(BaseModel):
|
32 |
features: list[float]
|
|
|
2 |
from fastapi.middleware.cors import CORSMiddleware
|
3 |
from pydantic import BaseModel
|
4 |
import numpy as np
|
|
|
5 |
import joblib
|
6 |
+
import requests
|
7 |
+
from io import BytesIO
|
8 |
|
9 |
app = FastAPI()
|
10 |
|
|
|
17 |
allow_headers=["*"],
|
18 |
)
|
19 |
|
20 |
+
MODEL_URL = "https://huggingface.co/GodfreyOwino/NPK_needs_mode2/resolve/main/npk_needs_model.joblib"
|
|
|
21 |
|
22 |
try:
|
23 |
+
response = requests.get(MODEL_URL)
|
24 |
+
response.raise_for_status()
|
25 |
+
model_bytes = BytesIO(response.content)
|
26 |
+
model = joblib.load(model_bytes)
|
27 |
print("Model loaded successfully")
|
28 |
except Exception as e:
|
29 |
print(f"Error loading model: {e}")
|
30 |
print(f"Error type: {type(e)}")
|
31 |
print(f"Error details: {str(e)}")
|
32 |
+
raise HTTPException(status_code=500, detail="Unable to load the model.")
|
33 |
|
34 |
class InputData(BaseModel):
|
35 |
features: list[float]
|