| | import os |
| | from fastapi import FastAPI, HTTPException |
| | from pydantic import BaseModel , Extra |
| | from transformers import pipeline |
| |
|
| | |
| | |
| | |
| | os.environ["HF_HOME"] = "/tmp/huggingface" |
| | os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface" |
| | os.environ["HF_DATASETS_CACHE"] = "/tmp/huggingface" |
| |
|
| | |
| | |
| | |
| | app = FastAPI(title="Routing Service - Space 2") |
| |
|
| | |
| | |
| | |
| | class RoutingRequest(BaseModel): |
| | text: str |
| |
|
| | class Config: |
| | extra = Extra.ignore |
| |
|
| | |
| | |
| | |
| | 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" |
| | ) |
| |
|
| | |
| | |
| | |
| | @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] |
| |
|
| | return {"department": department} |
| |
|
| | |
| | |
| | |
| | @app.get("/health") |
| | async def health(): |
| | return {"status": "ok"} |
| |
|