Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from fastapi.responses import FileResponse
|
| 3 |
+
from fastapi.staticfiles import StaticFiles
|
| 4 |
+
import pickle
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
# Serve static files like CSS
|
| 9 |
+
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 10 |
+
|
| 11 |
+
# Load the model
|
| 12 |
+
with open('logistic_model_reduced.pkl', 'rb') as file:
|
| 13 |
+
model = pickle.load('logistic_model_reduced.pkl')
|
| 14 |
+
|
| 15 |
+
@app.get("/")
|
| 16 |
+
def read_root():
|
| 17 |
+
return FileResponse("final_interactive_prototype_with_updated_title.html")
|
| 18 |
+
|
| 19 |
+
@app.post("/predict")
|
| 20 |
+
async def predict(features: list):
|
| 21 |
+
try:
|
| 22 |
+
prediction = model.predict([features])[0]
|
| 23 |
+
return {"prediction": int(prediction)}
|
| 24 |
+
except Exception as e:
|
| 25 |
+
raise HTTPException(status_code=500, detail=str(e))
|