Skip to content

Commit

Permalink
Merge pull request #8894 from khoaguin/fix-multiple-lines-tqdm
Browse files Browse the repository at this point in the history
[ux] fix tqdm prints multiple lines when `client.upload_dataset`
  • Loading branch information
shubham3121 authored Jun 10, 2024
2 parents 1b1490c + 8aa6304 commit 28822a9
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions packages/syft/src/syft/client/domain_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,25 +123,35 @@ def upload_dataset(self, dataset: CreateDataset) -> SyftSuccess | SyftError:
)
prompt_warning_message(message=message, confirm=True)

for asset in tqdm(dataset.asset_list, colour="green"):
print(f"Uploading: {asset.name}")
try:
twin = TwinObject(
private_obj=asset.data,
mock_obj=asset.mock,
syft_node_location=self.id,
syft_client_verify_key=self.verify_key,
)
twin._save_to_blob_storage()
except Exception as e:
return SyftError(message=f"Failed to create twin. {e}")
response = self.api.services.action.set(twin)
if isinstance(response, SyftError):
print(f"Failed to upload asset\n: {asset}")
return response
asset.action_id = twin.id
asset.node_uid = self.id
dataset_size += get_mb_size(asset.data)
with tqdm(
total=len(dataset.asset_list), colour="green", desc="Uploading"
) as pbar:
for asset in dataset.asset_list:
try:
twin = TwinObject(
private_obj=asset.data,
mock_obj=asset.mock,
syft_node_location=self.id,
syft_client_verify_key=self.verify_key,
)
twin._save_to_blob_storage()
except Exception as e:
tqdm.write(f"Failed to create twin for {asset.name}. {e}")
return SyftError(message=f"Failed to create twin. {e}")

response = self.api.services.action.set(twin)
if isinstance(response, SyftError):
tqdm.write(f"Failed to upload asset: {asset.name}")
return response

asset.action_id = twin.id
asset.node_uid = self.id
dataset_size += get_mb_size(asset.data)

# Update the progress bar and set the dynamic description
pbar.set_description(f"Uploading: {asset.name}")
pbar.update(1)

dataset.mb_size = dataset_size
valid = dataset.check()
if isinstance(valid, SyftError):
Expand Down

0 comments on commit 28822a9

Please sign in to comment.