9
9
10
10
import requests
11
11
from tqdm import tqdm
12
+ from tqdm .utils import CallbackIOWrapper
12
13
13
14
14
15
DEFAULT_ENDPOINT = "https://api.together.xyz/"
@@ -133,12 +134,17 @@ def upload_file(self, file: str) -> Dict[str, Union[str, int]]:
133
134
134
135
self .logger .info ("Uploading file..." )
135
136
137
+ file_size = os .stat (file ).st_size
136
138
with open (file , "rb" ) as f :
137
- response = requests .put (r2_signed_url , data = f )
139
+ with tqdm (
140
+ total = file_size , unit = "B" , unit_scale = True , unit_divisor = 1024
141
+ ) as t :
142
+ wrapped_file = CallbackIOWrapper (t .update , f , "read" )
143
+ response = requests .put (r2_signed_url , data = wrapped_file )
138
144
139
- self .logger .info ("> File uploaded." )
145
+ self .logger .info ("File uploaded." )
140
146
self .logger .debug (f"status code: { response .status_code } " )
141
- self .logger .info ("> Processing file..." )
147
+ self .logger .info ("Processing file..." )
142
148
preprocess_url = urllib .parse .urljoin (
143
149
self .endpoint_url , f"{ file_id } /preprocess"
144
150
)
@@ -148,7 +154,7 @@ def upload_file(self, file: str) -> Dict[str, Union[str, int]]:
148
154
headers = headers ,
149
155
)
150
156
151
- self .logger .info ("> File processed" )
157
+ self .logger .info ("File processed" )
152
158
self .logger .debug (f"Status code: { response .status_code } " )
153
159
154
160
except Exception as e :
0 commit comments