Spaces:
Paused
Paused
Upload testapi.py
Browse files- testapi.py +22 -0
testapi.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
import joblib
|
| 4 |
+
import numpy as np
|
| 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 = ([data.text])
|
| 16 |
+
feature = feature.lower
|
| 17 |
+
# Remove special characters and digits (keep only letters and spaces)
|
| 18 |
+
text = ''.join([char for char in feature if char.isalpha() or char.isspace()])
|
| 19 |
+
# Remove extra whitespace
|
| 20 |
+
text = ' '.join(feature.split())
|
| 21 |
+
prediction = model.predict(text)
|
| 22 |
+
return{"message":prediction}
|