MuhammadTechxone commited on
Commit
6aeab60
·
verified ·
1 Parent(s): e5b8d38

Update testapi.py

Browse files
Files changed (1) hide show
  1. 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 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}
 
 
 
 
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
+