Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +1 -0
- handler.py +26 -2
- requirements.txt +1 -1
Dockerfile
CHANGED
|
@@ -3,6 +3,7 @@ FROM python:3.10-slim
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
COPY requirements.txt .
|
|
|
|
| 6 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
|
| 8 |
COPY handler.py .
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
COPY requirements.txt .
|
| 6 |
+
RUN pip install --no-cache-dir torch==2.1.0 --index-url https://download.pytorch.org/whl/cpu
|
| 7 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 8 |
|
| 9 |
COPY handler.py .
|
handler.py
CHANGED
|
@@ -187,10 +187,24 @@ class TextFeatureExtractorEndpoint:
|
|
| 187 |
# FastAPI handler for deployment
|
| 188 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ #
|
| 189 |
|
| 190 |
-
from fastapi import FastAPI
|
| 191 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
| 192 |
from pydantic import BaseModel
|
| 193 |
-
from typing import Optional
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
|
| 195 |
app = FastAPI(title="Text Feature Extraction API", version="1.0.0")
|
| 196 |
app.add_middleware(
|
|
@@ -199,6 +213,16 @@ app.add_middleware(
|
|
| 199 |
allow_methods=["*"], allow_headers=["*"],
|
| 200 |
)
|
| 201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
extractor = TextFeatureExtractorEndpoint()
|
| 203 |
|
| 204 |
|
|
|
|
| 187 |
# FastAPI handler for deployment
|
| 188 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ #
|
| 189 |
|
| 190 |
+
from fastapi import FastAPI, Request
|
| 191 |
from fastapi.middleware.cors import CORSMiddleware
|
| 192 |
+
from fastapi.responses import JSONResponse
|
| 193 |
from pydantic import BaseModel
|
| 194 |
+
from typing import Optional, List, Dict
|
| 195 |
+
import traceback
|
| 196 |
+
|
| 197 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ #
|
| 198 |
+
# Constants & Defaults
|
| 199 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ #
|
| 200 |
+
|
| 201 |
+
DEFAULT_TEXT_FEATURES = {
|
| 202 |
+
"t0_explicit_free": 0.0, "t1_explicit_busy": 0.0,
|
| 203 |
+
"t2_avg_resp_len": 0.0, "t3_short_ratio": 0.0,
|
| 204 |
+
"t4_cognitive_load": 0.0, "t5_time_pressure": 0.0,
|
| 205 |
+
"t6_deflection": 0.0, "t7_sentiment": 0.0,
|
| 206 |
+
"t8_coherence": 0.5, "t9_latency": 0.0,
|
| 207 |
+
}
|
| 208 |
|
| 209 |
app = FastAPI(title="Text Feature Extraction API", version="1.0.0")
|
| 210 |
app.add_middleware(
|
|
|
|
| 213 |
allow_methods=["*"], allow_headers=["*"],
|
| 214 |
)
|
| 215 |
|
| 216 |
+
|
| 217 |
+
@app.exception_handler(Exception)
|
| 218 |
+
async def global_exception_handler(request: Request, exc: Exception):
|
| 219 |
+
print(f"[GLOBAL ERROR] {request.url}: {exc}")
|
| 220 |
+
traceback.print_exc()
|
| 221 |
+
return JSONResponse(
|
| 222 |
+
status_code=200,
|
| 223 |
+
content={**DEFAULT_TEXT_FEATURES, "_error": str(exc), "_handler": "global"},
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
extractor = TextFeatureExtractorEndpoint()
|
| 227 |
|
| 228 |
|
requirements.txt
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
# NLP
|
| 2 |
transformers==4.35.0
|
| 3 |
sentence-transformers==2.2.2
|
| 4 |
-
|
| 5 |
numpy==1.24.3
|
| 6 |
scikit-learn==1.3.2
|
| 7 |
|
|
|
|
| 1 |
# NLP
|
| 2 |
transformers==4.35.0
|
| 3 |
sentence-transformers==2.2.2
|
| 4 |
+
|
| 5 |
numpy==1.24.3
|
| 6 |
scikit-learn==1.3.2
|
| 7 |
|