5252 Tokens ,
5353)
5454from nuclia_models .predict .remi import RemiRequest , RemiResponse
55+ import os
56+ from tqdm import tqdm
57+ import asyncio
5558
59+ MB = 1024 * 1024
60+ CHUNK_SIZE = 10 * MB
5661SENTENCE_PREDICT = "/api/v1/predict/sentence"
5762CHAT_PREDICT = "/api/v1/predict/chat"
5863SUMMARIZE_PREDICT = "/api/v1/predict/summarize"
@@ -672,10 +677,26 @@ async def process_file(
672677
673678 headers = self .headers .copy ()
674679 headers ["X-FILENAME" ] = base64 .b64encode (filename .encode ()).decode ()
675- async with aiofiles .open (path , "rb" ) as file_to_upload :
676- data = await file_to_upload .read ()
677680
678- resp = await self .client .post (upload_endpoint , content = data , headers = headers )
681+ async def iterator (path : str ):
682+ total_size = os .path .getsize (path )
683+ with tqdm (
684+ desc = "Uploading data" ,
685+ total = total_size ,
686+ unit = "iB" ,
687+ unit_scale = True ,
688+ ) as pbar :
689+ async with aiofiles .open (path , "rb" ) as f :
690+ while True :
691+ chunk = await f .read (CHUNK_SIZE )
692+ if not chunk :
693+ break
694+ pbar .update (len (chunk ))
695+ yield chunk
696+
697+ resp = await self .client .post (
698+ upload_endpoint , content = iterator (path ), headers = headers
699+ )
679700
680701 payload = PushPayload (
681702 uuid = None , source = Source .HTTP , kbid = RestrictedIDString (kbid )
@@ -697,7 +718,7 @@ async def wait_for_processing(
697718 count = timeout
698719 while status .completed is False and status .failed is False and count > 0 :
699720 status = await self .processing_id_status (response .processing_id )
700- sleep (3 )
721+ await asyncio . sleep (1 )
701722 count -= 1
702723
703724 bm = None
0 commit comments