vrkforever's picture
Add application file
4ea700c
raw
history blame
775 Bytes
import nltk
from fastapi import FastAPI, Form
from fastapi.responses import PlainTextResponse
import joblib
# Download necessary NLTK resources
nltk.download('wordnet', quiet=True)
nltk.download('stopwords', quiet=True)
# Load the trained model
model = joblib.load('disaster_classification_model.joblib')
app = FastAPI()
@app.post("/predict", response_class=PlainTextResponse)
async def predict(text: str = Form(...)):
# The preprocessing is now handled by the loaded pipeline
prediction = model.predict([text])[0]
return "disaster" if prediction == 1 else "not"
@app.get("/")
async def root():
return {"message": "Welcome to the Disaster Classification API"}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=7860)