File size: 1,714 Bytes
0f5b2b6
9c7af28
025579b
00a3f62
9c7af28
35e526a
 
 
f156d8f
 
 
 
35e526a
 
 
 
 
9c7af28
 
 
 
 
 
025579b
 
 
9c7af28
00a3f62
9c7af28
8560891
00a3f62
 
 
 
 
 
 
9c7af28
 
 
 
 
 
 
 
 
 
00a3f62
 
9c7af28
f8a0e18
9c7af28
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel , Extra
from transformers import pipeline

# -------------------------------
# Set Hugging Face cache to writable directory
# -------------------------------
os.environ["HF_HOME"] = "/tmp/huggingface"
os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface"
os.environ["HF_DATASETS_CACHE"] = "/tmp/huggingface"

# -------------------------------
# FastAPI app
# -------------------------------
app = FastAPI(title="Routing Service - Space 2")

# -------------------------------
# Request Model
# -------------------------------
class RoutingRequest(BaseModel):
    text: str

    class Config:
        extra = Extra.ignore  # allow extra fields like user_email

# -------------------------------
# Load Zero-Shot Classifier
# -------------------------------
DEPARTMENTS = ['Account', 'Software', 'Network', 'Security', 'Hardware',
               'Infrastructure', 'Licensing', 'Communication', 'RemoteWork',
               'Training', 'Performance']

classifier = pipeline(
    "zero-shot-classification",
    model="MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli"
)

# -------------------------------
# Routing Endpoint
# -------------------------------
@app.post("/route")
async def route_ticket(req: RoutingRequest):
    text = req.text
    if not text:
        raise HTTPException(status_code=400, detail="Text cannot be empty")

    result = classifier(text, DEPARTMENTS)
    department = result["labels"][0]  # highest scoring department

    return {"department": department}

# -------------------------------
# Health Check
# -------------------------------
@app.get("/health")
async def health():
    return {"status": "ok"}