FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
openai-python/openai/upload_progress.py at main · lufarapCode/openai-python · GitHub
lufarapCode
/
openai-python
Public
forked from
openai/openai-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
openai-python
/
openai
/
upload_progress.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
52 lines (37 loc) · 1.16 KB
Breadcrumbs
openai-python
/
openai
/
upload_progress.py
Copy path
File metadata and controls
52 lines (37 loc) · 1.16 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import
io
class
CancelledError
(
Exception
):
def
__init__
(
self
,
msg
):
self
.
msg
=
msg
Exception
.
__init__
(
self
,
msg
)
def
__str__
(
self
):
return
self
.
msg
__repr__
=
__str__
class
BufferReader
(
io
.
BytesIO
):
def
__init__
(
self
,
buf
=
b""
,
desc
=
None
):
self
.
_len
=
len
(
buf
)
io
.
BytesIO
.
__init__
(
self
,
buf
)
self
.
_progress
=
0
self
.
_callback
=
progress
(
len
(
buf
),
desc
=
desc
)
def
__len__
(
self
):
return
self
.
_len
def
read
(
self
,
n
=
-
1
):
chunk
=
io
.
BytesIO
.
read
(
self
,
n
)
self
.
_progress
+=
len
(
chunk
)
if
self
.
_callback
:
try
:
self
.
_callback
(
self
.
_progress
)
except
Exception
as
e
:
# catches exception from the callback
raise
CancelledError
(
"The upload was cancelled: {}"
.
format
(
e
))
return
chunk
def
progress
(
total
,
desc
):
import
tqdm
# type: ignore
meter
=
tqdm
.
tqdm
(
total
=
total
,
unit_scale
=
True
,
desc
=
desc
)
def
incr
(
progress
):
meter
.
n
=
progress
if
progress
==
total
:
meter
.
close
()
else
:
meter
.
refresh
()
return
incr
def
MB
(
i
):
return
int
(
i
//
1024
**
2
)
Back
|
FazBrowse Home
|
New Git URL