Spaces:
Paused
Paused
Update testapi.py
Browse files- testapi.py +25 -22
testapi.py
CHANGED
|
@@ -1,22 +1,25 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
from pydantic import BaseModel
|
| 3 |
-
import joblib
|
| 4 |
-
import
|
| 5 |
-
app = FastAPI(title = "Psychotherapy")
|
| 6 |
-
model = joblib.load("psychotherapy_svm_model.pkl")
|
| 7 |
-
|
| 8 |
-
class inputdata(BaseModel):
|
| 9 |
-
text: str
|
| 10 |
-
@app.get("/")
|
| 11 |
-
def home():
|
| 12 |
-
return {"message":"Welcome to psychoAPI"}
|
| 13 |
-
@app.post("/predict")
|
| 14 |
-
def predict(data: inputdata):
|
| 15 |
-
feature =
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
# Remove
|
| 20 |
-
text = '
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
import joblib
|
| 4 |
+
import pandas as pd
|
| 5 |
+
app = FastAPI(title = "Psychotherapy")
|
| 6 |
+
model = joblib.load("psychotherapy_svm_model.pkl")
|
| 7 |
+
|
| 8 |
+
class inputdata(BaseModel):
|
| 9 |
+
text: str
|
| 10 |
+
@app.get("/")
|
| 11 |
+
def home():
|
| 12 |
+
return {"message":"Welcome to psychoAPI"}
|
| 13 |
+
@app.post("/predict")
|
| 14 |
+
def predict(data: inputdata):
|
| 15 |
+
feature = pd.DataFrame({
|
| 16 |
+
"text": [data.text]
|
| 17 |
+
})
|
| 18 |
+
feature = feature.str.lower()
|
| 19 |
+
# Remove special characters and digits (keep only letters and spaces)
|
| 20 |
+
text = ''.join([char for char in feature if char.isalpha() or char.isspace()])
|
| 21 |
+
# Remove extra whitespace
|
| 22 |
+
text = ' '.join(feature.split())
|
| 23 |
+
prediction = model.predict(text)
|
| 24 |
+
return{"message":prediction}
|
| 25 |
+
|