vrkforever
commited on
Commit
•
4ea700c
1
Parent(s):
01944f5
Add application file
Browse files- app.py +27 -0
- requirements.txt +7 -0
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import nltk
|
2 |
+
from fastapi import FastAPI, Form
|
3 |
+
from fastapi.responses import PlainTextResponse
|
4 |
+
import joblib
|
5 |
+
|
6 |
+
# Download necessary NLTK resources
|
7 |
+
nltk.download('wordnet', quiet=True)
|
8 |
+
nltk.download('stopwords', quiet=True)
|
9 |
+
|
10 |
+
# Load the trained model
|
11 |
+
model = joblib.load('disaster_classification_model.joblib')
|
12 |
+
|
13 |
+
app = FastAPI()
|
14 |
+
|
15 |
+
@app.post("/predict", response_class=PlainTextResponse)
|
16 |
+
async def predict(text: str = Form(...)):
|
17 |
+
# The preprocessing is now handled by the loaded pipeline
|
18 |
+
prediction = model.predict([text])[0]
|
19 |
+
return "disaster" if prediction == 1 else "not"
|
20 |
+
|
21 |
+
@app.get("/")
|
22 |
+
async def root():
|
23 |
+
return {"message": "Welcome to the Disaster Classification API"}
|
24 |
+
|
25 |
+
if __name__ == "__main__":
|
26 |
+
import uvicorn
|
27 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pandas
|
2 |
+
scikit-learn
|
3 |
+
nltk
|
4 |
+
fastapi
|
5 |
+
uvicorn
|
6 |
+
joblib
|
7 |
+
python-multipart
|