orreryspaceapp / app.py
Sushan
Model deployed
7aa2125
raw
history blame
846 Bytes
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import pandas as pd
import joblib
# Load the trained model
model = joblib.load("model.pkl") # Ensure your model is saved as 'model.pkl'
app = FastAPI()
# Add CORS middleware to allow requests from any origin
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Allow all origins (adjust if needed)
allow_credentials=True,
allow_methods=["*"], # Allow all methods (GET, POST, etc.)
allow_headers=["*"], # Allow all headers
)
@app.post("/predict")
async def predict(features: dict):
# Convert the input into a DataFrame
input_data = pd.DataFrame([features])
# Make prediction using the trained model
prediction = model.predict(input_data)
return {"is_potentially_hazardous_asteroid": int(prediction[0])}