Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## 4.4.5 (unreleased)


- Nothing changed yet.
- Fix blocking code on upload and wait routine


## 4.4.4 (2025-01-10)
Expand Down
29 changes: 25 additions & 4 deletions nuclia/lib/nua.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@
Tokens,
)
from nuclia_models.predict.remi import RemiRequest, RemiResponse
import os
from tqdm import tqdm
import asyncio

MB = 1024 * 1024
CHUNK_SIZE = 10 * MB
SENTENCE_PREDICT = "/api/v1/predict/sentence"
CHAT_PREDICT = "/api/v1/predict/chat"
SUMMARIZE_PREDICT = "/api/v1/predict/summarize"
Expand Down Expand Up @@ -672,10 +677,26 @@ async def process_file(

headers = self.headers.copy()
headers["X-FILENAME"] = base64.b64encode(filename.encode()).decode()
async with aiofiles.open(path, "rb") as file_to_upload:
data = await file_to_upload.read()

resp = await self.client.post(upload_endpoint, content=data, headers=headers)
async def iterator(path: str):
total_size = os.path.getsize(path)
with tqdm(
desc="Uploading data",
total=total_size,
unit="iB",
unit_scale=True,
) as pbar:
async with aiofiles.open(path, "rb") as f:
while True:
chunk = await f.read(CHUNK_SIZE)
if not chunk:
break
pbar.update(len(chunk))
yield chunk

resp = await self.client.post(
upload_endpoint, content=iterator(path), headers=headers
)

payload = PushPayload(
uuid=None, source=Source.HTTP, kbid=RestrictedIDString(kbid)
Expand All @@ -697,7 +718,7 @@ async def wait_for_processing(
count = timeout
while status.completed is False and status.failed is False and count > 0:
status = await self.processing_id_status(response.processing_id)
sleep(3)
await asyncio.sleep(1)
count -= 1

bm = None
Expand Down
Loading