MJobe commited on
Commit
2c29573
·
verified ·
1 Parent(s): 6a96e5e

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -8
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
- # Create a thread pool executor for running the synchronous function asynchronously
291
  loop = asyncio.get_running_loop()
292
- with ThreadPoolExecutor() as executor:
293
- # Run the classification pipeline in a separate thread
294
- result = await loop.run_in_executor(
295
- executor,
296
- lambda: nlp_sequence_classification(statement, labels, multi_label=False)
297
- )
298
 
299
- # Extract the best label and score from the result
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