Spaces:
Sleeping
Sleeping
Update modelLoanAPI.py
Browse files- modelLoanAPI.py +11 -2
modelLoanAPI.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
-
|
| 2 |
from fastapi import FastAPI, HTTPException
|
| 3 |
from fastapi.responses import JSONResponse, FileResponse
|
|
|
|
| 4 |
import pandas as pd
|
| 5 |
import numpy as np
|
| 6 |
from sklearn.ensemble import RandomForestClassifier, GradientBoostingRegressor
|
|
@@ -19,6 +19,15 @@ warnings.filterwarnings("ignore")
|
|
| 19 |
|
| 20 |
app = FastAPI()
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
class WorkerInput(BaseModel):
|
| 23 |
worker_id: int
|
| 24 |
|
|
@@ -254,4 +263,4 @@ async def get_forecast_plot(worker_id: int):
|
|
| 254 |
if os.path.exists(plot_filename):
|
| 255 |
return FileResponse(plot_filename, media_type="image/jpeg", filename=f"worker_{worker_id}_forecast.jpg")
|
| 256 |
else:
|
| 257 |
-
raise HTTPException(status_code=404, detail=f"Plot for worker_id {worker_id} not found")
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, HTTPException
|
| 2 |
from fastapi.responses import JSONResponse, FileResponse
|
| 3 |
+
from fastapi.middleware.cors import CORSMiddleware # Import CORSMiddleware
|
| 4 |
import pandas as pd
|
| 5 |
import numpy as np
|
| 6 |
from sklearn.ensemble import RandomForestClassifier, GradientBoostingRegressor
|
|
|
|
| 19 |
|
| 20 |
app = FastAPI()
|
| 21 |
|
| 22 |
+
# Add CORS middleware
|
| 23 |
+
app.add_middleware(
|
| 24 |
+
CORSMiddleware,
|
| 25 |
+
allow_origins=["*"], # Allows all origins; replace with specific origins in production
|
| 26 |
+
allow_credentials=True,
|
| 27 |
+
allow_methods=["*"], # Allows all methods (GET, POST, etc.)
|
| 28 |
+
allow_headers=["*"], # Allows all headers
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
class WorkerInput(BaseModel):
|
| 32 |
worker_id: int
|
| 33 |
|
|
|
|
| 263 |
if os.path.exists(plot_filename):
|
| 264 |
return FileResponse(plot_filename, media_type="image/jpeg", filename=f"worker_{worker_id}_forecast.jpg")
|
| 265 |
else:
|
| 266 |
+
raise HTTPException(status_code=404, detail=f"Plot for worker_id {worker_id} not found")
|