Spaces:
Paused
Paused
Delete testapi.py
Browse files- testapi.py +0 -46
testapi.py
DELETED
|
@@ -1,46 +0,0 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
from pydantic import BaseModel
|
| 3 |
-
import joblib
|
| 4 |
-
import pandas as pd
|
| 5 |
-
|
| 6 |
-
# Add this for Hugging Face Spaces
|
| 7 |
-
import sys
|
| 8 |
-
print("Python path:", sys.path)
|
| 9 |
-
|
| 10 |
-
app = FastAPI(title="Psychotherapy")
|
| 11 |
-
|
| 12 |
-
# Add this middleware for Hugging Face Spaces
|
| 13 |
-
@app.middleware("http")
|
| 14 |
-
async def add_process_time_header(request, call_next):
|
| 15 |
-
response = await call_next(request)
|
| 16 |
-
return response
|
| 17 |
-
|
| 18 |
-
model = joblib.load("psychotherapy_svm_model.pkl")
|
| 19 |
-
|
| 20 |
-
def preprocess_text(text):
|
| 21 |
-
"""Basic text preprocessing"""
|
| 22 |
-
text = text.lower()
|
| 23 |
-
text = ''.join([char for char in text if char.isalpha() or char.isspace()])
|
| 24 |
-
text = ' '.join(text.split())
|
| 25 |
-
return text
|
| 26 |
-
|
| 27 |
-
class inputdata(BaseModel):
|
| 28 |
-
text: str
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
@app.post("/predict")
|
| 33 |
-
def predict(data: inputdata):
|
| 34 |
-
df = pd.DataFrame({
|
| 35 |
-
"text": [data.text]
|
| 36 |
-
})
|
| 37 |
-
|
| 38 |
-
df['clean_text'] = df['text'].apply(preprocess_text)
|
| 39 |
-
prediction = model.predict(df['clean_text'])
|
| 40 |
-
|
| 41 |
-
# Convert prediction to list if it's numpy array for JSON serialization
|
| 42 |
-
if hasattr(prediction, 'tolist'):
|
| 43 |
-
prediction = prediction.tolist()
|
| 44 |
-
|
| 45 |
-
return {"message": prediction}
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|