Spaces:
Sleeping
Sleeping
Update app/main.py
Browse files- app/main.py +43 -0
app/main.py
CHANGED
|
@@ -35,6 +35,28 @@ def classify(pipe, text):
|
|
| 35 |
}
|
| 36 |
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
def detect_sarcasm_text(request: SarcasmRequest):
|
| 40 |
# # PHASE 3: Sarcasm Detection
|
|
@@ -192,6 +214,27 @@ async def detect_sarcasm(
|
|
| 192 |
|
| 193 |
|
| 194 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
from app.embedding import generate_embeddings
|
| 197 |
|
|
|
|
| 35 |
}
|
| 36 |
|
| 37 |
|
| 38 |
+
def detect_absa(request: AbsaRequest):
|
| 39 |
+
absa_model = models.absa()
|
| 40 |
+
|
| 41 |
+
start = time.perf_counter()
|
| 42 |
+
|
| 43 |
+
# Format input untuk ABSA: [sentence] [SEP] [aspect]
|
| 44 |
+
text_input = f"{request.text} [SEP] {request.aspect}"
|
| 45 |
+
|
| 46 |
+
# Prediksi sentimen
|
| 47 |
+
pred = absa_pipe(text_input)
|
| 48 |
+
|
| 49 |
+
return {
|
| 50 |
+
"absa":pred,
|
| 51 |
+
"metadata": {
|
| 52 |
+
"pipeline": ["absa"],
|
| 53 |
+
"inference_time_ms": round(
|
| 54 |
+
(time.perf_counter() - start) * 1000,
|
| 55 |
+
2
|
| 56 |
+
)
|
| 57 |
+
},
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
|
| 61 |
def detect_sarcasm_text(request: SarcasmRequest):
|
| 62 |
# # PHASE 3: Sarcasm Detection
|
|
|
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
+
@app.post("/v1/absa")
|
| 218 |
+
async def absa(
|
| 219 |
+
request: AbsaRequest
|
| 220 |
+
x_api_key: str | None = Header(default=None)
|
| 221 |
+
):
|
| 222 |
+
verify_api_key(x_api_key)
|
| 223 |
+
|
| 224 |
+
try:
|
| 225 |
+
return await run_in_threadpool(
|
| 226 |
+
detect_absa,
|
| 227 |
+
request
|
| 228 |
+
)
|
| 229 |
+
except HTTPException:
|
| 230 |
+
raise
|
| 231 |
+
except Exception as exc:
|
| 232 |
+
raise HTTPException(
|
| 233 |
+
status_code=500,
|
| 234 |
+
detail=str(exc)
|
| 235 |
+
)
|
| 236 |
+
|
| 237 |
+
|
| 238 |
|
| 239 |
from app.embedding import generate_embeddings
|
| 240 |
|