asdfasdfdsafdsa commited on
Commit
bf696db
Β·
verified Β·
1 Parent(s): 508f678

Upload api.py

Browse files
Files changed (1) hide show
  1. api.py +15 -0
api.py CHANGED
@@ -364,11 +364,14 @@ async def correct_text(request: CorrectionRequest):
364
  if len(request.text) > 100000:
365
  raise HTTPException(status_code=400, detail="Text too long (max 100000 characters)")
366
 
 
 
367
  # Process text
368
  corrected = process_text(request.text)
369
 
370
  # Calculate processing time
371
  processing_time = (time.time() - start_time) * 1000
 
372
 
373
  # Include timing if requested
374
  response = CorrectionResponse(
@@ -401,6 +404,8 @@ async def correct_batch(request: BatchCorrectionRequest):
401
  if not request.texts:
402
  raise HTTPException(status_code=400, detail="No texts provided")
403
 
 
 
404
  # Validate text lengths
405
  validated_texts = []
406
  for text in request.texts:
@@ -411,10 +416,18 @@ async def correct_batch(request: BatchCorrectionRequest):
411
 
412
  # Process all texts in batch (GPU efficient!)
413
  # Step 1: Grammar correction (batched)
 
 
414
  gec_corrected_texts = apply_gec_correction_batch(validated_texts)
 
 
415
 
416
  # Step 2: Punctuation and capitalization (batched)
 
 
417
  final_texts = apply_punctuation_batch(gec_corrected_texts)
 
 
418
 
419
  # Mark texts that were too long
420
  corrected_texts = []
@@ -427,6 +440,8 @@ async def correct_batch(request: BatchCorrectionRequest):
427
  # Calculate processing time
428
  processing_time = (time.time() - start_time) * 1000
429
 
 
 
430
  response = BatchCorrectionResponse(
431
  success=True,
432
  corrected_texts=corrected_texts
 
364
  if len(request.text) > 100000:
365
  raise HTTPException(status_code=400, detail="Text too long (max 100000 characters)")
366
 
367
+ logger.info(f"πŸ“ Single text request received ({len(request.text)} chars)")
368
+
369
  # Process text
370
  corrected = process_text(request.text)
371
 
372
  # Calculate processing time
373
  processing_time = (time.time() - start_time) * 1000
374
+ logger.info(f"βœ… Completed in {processing_time:.1f}ms")
375
 
376
  # Include timing if requested
377
  response = CorrectionResponse(
 
404
  if not request.texts:
405
  raise HTTPException(status_code=400, detail="No texts provided")
406
 
407
+ logger.info(f"πŸ“¦ Batch request received: {len(request.texts)} texts")
408
+
409
  # Validate text lengths
410
  validated_texts = []
411
  for text in request.texts:
 
416
 
417
  # Process all texts in batch (GPU efficient!)
418
  # Step 1: Grammar correction (batched)
419
+ logger.info(f"πŸ”§ Starting GEC batch processing ({len(validated_texts)} texts)...")
420
+ gec_start = time.time()
421
  gec_corrected_texts = apply_gec_correction_batch(validated_texts)
422
+ gec_time = (time.time() - gec_start) * 1000
423
+ logger.info(f"βœ“ GEC completed in {gec_time:.1f}ms")
424
 
425
  # Step 2: Punctuation and capitalization (batched)
426
+ logger.info(f"πŸ“ Starting punctuation batch processing...")
427
+ punct_start = time.time()
428
  final_texts = apply_punctuation_batch(gec_corrected_texts)
429
+ punct_time = (time.time() - punct_start) * 1000
430
+ logger.info(f"βœ“ Punctuation completed in {punct_time:.1f}ms")
431
 
432
  # Mark texts that were too long
433
  corrected_texts = []
 
440
  # Calculate processing time
441
  processing_time = (time.time() - start_time) * 1000
442
 
443
+ logger.info(f"βœ… Batch completed: {len(corrected_texts)} texts in {processing_time:.1f}ms (avg {processing_time/len(corrected_texts):.1f}ms/text)")
444
+
445
  response = BatchCorrectionResponse(
446
  success=True,
447
  corrected_texts=corrected_texts