|
import nltk |
|
from fastapi import FastAPI, Form |
|
from fastapi.responses import PlainTextResponse |
|
import joblib |
|
|
|
|
|
nltk.download('wordnet', quiet=True) |
|
nltk.download('stopwords', quiet=True) |
|
|
|
|
|
model = joblib.load('disaster_classification_model.joblib') |
|
|
|
app = FastAPI() |
|
|
|
@app.post("/predict", response_class=PlainTextResponse) |
|
async def predict(text: str = Form(...)): |
|
|
|
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) |