Commit ·
88d9793
1
Parent(s): cdd9d8d
changed app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import nltk
|
| 2 |
-
from fastapi import FastAPI
|
| 3 |
-
from fastapi.responses import
|
|
|
|
| 4 |
import joblib
|
| 5 |
|
| 6 |
# Download necessary NLTK resources
|
|
@@ -12,11 +13,16 @@ model = joblib.load('disaster_classification_model.joblib')
|
|
| 12 |
|
| 13 |
app = FastAPI()
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# The preprocessing is now handled by the loaded pipeline
|
| 18 |
prediction = model.predict([text])[0]
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
@app.get("/")
|
| 22 |
async def root():
|
|
@@ -24,4 +30,4 @@ async def root():
|
|
| 24 |
|
| 25 |
if __name__ == "__main__":
|
| 26 |
import uvicorn
|
| 27 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
import nltk
|
| 2 |
+
from fastapi import FastAPI
|
| 3 |
+
from fastapi.responses import JSONResponse
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
import joblib
|
| 6 |
|
| 7 |
# Download necessary NLTK resources
|
|
|
|
| 13 |
|
| 14 |
app = FastAPI()
|
| 15 |
|
| 16 |
+
class TextRequest(BaseModel):
|
| 17 |
+
text: str
|
| 18 |
+
|
| 19 |
+
@app.post("/predict")
|
| 20 |
+
async def predict(request: TextRequest):
|
| 21 |
+
text = request.text
|
| 22 |
# The preprocessing is now handled by the loaded pipeline
|
| 23 |
prediction = model.predict([text])[0]
|
| 24 |
+
result = "disaster" if prediction == 1 else "not"
|
| 25 |
+
return JSONResponse(content={"output": result})
|
| 26 |
|
| 27 |
@app.get("/")
|
| 28 |
async def root():
|
|
|
|
| 30 |
|
| 31 |
if __name__ == "__main__":
|
| 32 |
import uvicorn
|
| 33 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|