Upload 3 files
Browse files- Dockerfile +20 -0
- app.py +52 -0
- requirements.txt +0 -0
Dockerfile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Base image
|
| 2 |
+
FROM python:3.11-slim
|
| 3 |
+
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy requirements
|
| 8 |
+
COPY requirements.txt .
|
| 9 |
+
|
| 10 |
+
# Install dependencies
|
| 11 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 12 |
+
|
| 13 |
+
# Copy app.py
|
| 14 |
+
COPY . .
|
| 15 |
+
|
| 16 |
+
# Expose port
|
| 17 |
+
EXPOSE 7860
|
| 18 |
+
|
| 19 |
+
# Run FastAPI server
|
| 20 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
app = FastAPI(title="Routing Service - Space 2")
|
| 7 |
+
|
| 8 |
+
# -------------------------------
|
| 9 |
+
# Request Model
|
| 10 |
+
# -------------------------------
|
| 11 |
+
class RoutingRequest(BaseModel):
|
| 12 |
+
text: str
|
| 13 |
+
|
| 14 |
+
# -------------------------------
|
| 15 |
+
# Load Routing Model (DeBERTa MNLI)
|
| 16 |
+
# -------------------------------
|
| 17 |
+
MODEL_NAME = "MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli"
|
| 18 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 19 |
+
model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME)
|
| 20 |
+
|
| 21 |
+
# Define your possible departments / labels
|
| 22 |
+
DEPARTMENTS = ["Account", "Software", "Network", "Security", "Hardware",
|
| 23 |
+
"Infrastructure", "Licensing", "Communication", "RemoteWork",
|
| 24 |
+
"Training", "Performance"]
|
| 25 |
+
|
| 26 |
+
# -------------------------------
|
| 27 |
+
# Routing Endpoint
|
| 28 |
+
# -------------------------------
|
| 29 |
+
@app.post("/route")
|
| 30 |
+
async def route_ticket(req: RoutingRequest):
|
| 31 |
+
text = req.text
|
| 32 |
+
if not text:
|
| 33 |
+
raise HTTPException(status_code=400, detail="Text cannot be empty")
|
| 34 |
+
|
| 35 |
+
# Tokenize
|
| 36 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True)
|
| 37 |
+
outputs = model(**inputs)
|
| 38 |
+
logits = outputs.logits[0]
|
| 39 |
+
|
| 40 |
+
# Simple mapping: choose max logit index as department (demo)
|
| 41 |
+
# For a real hackathon, you may map labels more carefully
|
| 42 |
+
department_idx = torch.argmax(logits).item() % len(DEPARTMENTS)
|
| 43 |
+
department = DEPARTMENTS[department_idx]
|
| 44 |
+
|
| 45 |
+
return {"department": department}
|
| 46 |
+
|
| 47 |
+
# -------------------------------
|
| 48 |
+
# Health Check
|
| 49 |
+
# -------------------------------
|
| 50 |
+
@app.get("/health")
|
| 51 |
+
async def health():
|
| 52 |
+
return {"status": "ok"}
|
requirements.txt
ADDED
|
File without changes
|