Spaces:
Paused
Paused
Upload 2 files
Browse files- mental_health_api.py +39 -0
- psychotherapy_svm_model.pkl +2 -2
mental_health_api.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# Create a preprocessing function
|
| 9 |
+
def preprocess_text(text):
|
| 10 |
+
"""Basic text preprocessing"""
|
| 11 |
+
# Convert to lowercase
|
| 12 |
+
text = text.lower()
|
| 13 |
+
# Remove special characters and digits (keep only letters and spaces)
|
| 14 |
+
text = ''.join([char for char in text if char.isalpha() or char.isspace()])
|
| 15 |
+
# Remove extra whitespace
|
| 16 |
+
text = ' '.join(text.split())
|
| 17 |
+
return text
|
| 18 |
+
|
| 19 |
+
class inputdata(BaseModel):
|
| 20 |
+
text: str
|
| 21 |
+
@app.get("/")
|
| 22 |
+
def home():
|
| 23 |
+
return {"message":"Welcome to psychoAPI"}
|
| 24 |
+
@app.post("/predict")
|
| 25 |
+
def predict(data: inputdata):
|
| 26 |
+
df = pd.DataFrame({
|
| 27 |
+
"text": [data.text]
|
| 28 |
+
})
|
| 29 |
+
|
| 30 |
+
# Apply preprocessing
|
| 31 |
+
df['clean_text'] = df['text'].apply(preprocess_text)
|
| 32 |
+
|
| 33 |
+
#feature = feature.str.lower()
|
| 34 |
+
# Remove special characters and digits (keep only letters and spaces)
|
| 35 |
+
#text = ''.join([char for char in feature if char.isalpha() or char.isspace()])
|
| 36 |
+
# Remove extra whitespace
|
| 37 |
+
#text = ' '.join(text.split())
|
| 38 |
+
prediction = model.predict(df['clean_text'])
|
| 39 |
+
return{"message":prediction}
|
psychotherapy_svm_model.pkl
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:022672cc70ccb117f6ab52ef12f93d87e8d882cd9d110726573ba84843406ea0
|
| 3 |
+
size 364152
|