Spaces:
Runtime error
Runtime error
shubh2014shiv
commited on
Commit
•
09fd64c
1
Parent(s):
01f0d5c
Upload GD_download.py
Browse filesPython Code for downloading model from Google Drive
- GD_download.py +30 -0
GD_download.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
|
3 |
+
def download_file_from_google_drive(id, destination):
|
4 |
+
URL = "https://docs.google.com/uc?export=download"
|
5 |
+
|
6 |
+
session = requests.Session()
|
7 |
+
|
8 |
+
response = session.get(URL, params = { 'id' : id }, stream = True)
|
9 |
+
token = get_confirm_token(response)
|
10 |
+
|
11 |
+
if token:
|
12 |
+
params = { 'id' : id, 'confirm' : token }
|
13 |
+
response = session.get(URL, params = params, stream = True)
|
14 |
+
|
15 |
+
save_response_content(response, destination)
|
16 |
+
|
17 |
+
def get_confirm_token(response):
|
18 |
+
for key, value in response.cookies.items():
|
19 |
+
if key.startswith('download_warning'):
|
20 |
+
return value
|
21 |
+
|
22 |
+
return None
|
23 |
+
|
24 |
+
def save_response_content(response, destination):
|
25 |
+
CHUNK_SIZE = 32768
|
26 |
+
|
27 |
+
with open(destination, "wb") as f:
|
28 |
+
for chunk in response.iter_content(CHUNK_SIZE):
|
29 |
+
if chunk: # filter out keep-alive new chunks
|
30 |
+
f.write(chunk)
|