Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -284,19 +284,19 @@ labels = [
|
|
284 |
"Status Check (possibly)"
|
285 |
]
|
286 |
|
|
|
|
|
287 |
@app.post("/fast_classify/", description="Quickly classify text into predefined categories.")
|
288 |
async def fast_classify_text(statement: str = Form(...)):
|
289 |
try:
|
290 |
-
#
|
291 |
loop = asyncio.get_running_loop()
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
lambda: nlp_sequence_classification(statement, labels, multi_label=False)
|
297 |
-
)
|
298 |
|
299 |
-
#
|
300 |
best_label = result["labels"][0]
|
301 |
best_score = result["scores"][0]
|
302 |
|
|
|
284 |
"Status Check (possibly)"
|
285 |
]
|
286 |
|
287 |
+
executor = ThreadPoolExecutor(max_workers=10)
|
288 |
+
|
289 |
@app.post("/fast_classify/", description="Quickly classify text into predefined categories.")
|
290 |
async def fast_classify_text(statement: str = Form(...)):
|
291 |
try:
|
292 |
+
# Use run_in_executor with a pre-loaded model for quicker response
|
293 |
loop = asyncio.get_running_loop()
|
294 |
+
result = await loop.run_in_executor(
|
295 |
+
executor,
|
296 |
+
lambda: nlp_sequence_classification(statement, labels, multi_label=False)
|
297 |
+
)
|
|
|
|
|
298 |
|
299 |
+
# Process result to extract label and score
|
300 |
best_label = result["labels"][0]
|
301 |
best_score = result["scores"][0]
|
302 |
|