File size: 775 Bytes
4ea700c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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)