File size: 979 Bytes
4c20ed7
 
 
 
cecf8bc
4c20ed7
 
 
cecf8bc
 
 
 
 
 
 
4c20ed7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cecf8bc
 
 
4c20ed7
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import re
import joblib
from fastapi import FastAPI, Request
from pydantic import BaseModel
from fastapi.middleware.cors import CORSMiddleware

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # Or restrict to your domain
    allow_methods=["*"],
    allow_headers=["*"],
)

# Load model and vectorizer
model = joblib.load("team_classifier_model.joblib") 
vectorizer = joblib.load("tfidf_vectorizer.joblib")


def clean_text(text):
    text = re.sub(r"\s+", " ", str(text))
    text = re.sub(r"[^\w\s]", "", text)
    return text.lower().strip()


class InputText(BaseModel):
    subject: str
    message: str

@app.get("/")
def root():
    return {"status": "running", "message": "Use POST /classify"}

@app.post("/classify")
async def classify_ticket(data: InputText):
    combined = clean_text(f"{data.subject} {data.message}")
    vec = vectorizer.transform([combined])
    prediction = model.predict(vec)[0]
    return {"team": prediction}