Spaces:
Sleeping
Sleeping
rogerxavier
commited on
Commit
•
6b71423
1
Parent(s):
7157ea6
Update task/_0上传遮罩.py
Browse files- task/_0上传遮罩.py +51 -41
task/_0上传遮罩.py
CHANGED
@@ -1,42 +1,52 @@
|
|
1 |
-
|
2 |
-
#批量上传
|
3 |
-
import os
|
4 |
-
import requests
|
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 |
-
for
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
#
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
upload_mask_to_space(baseUrl='https://rogerxavier-moviepy-with-manga-test.hf.space', mask_path='mask')#破案了,必须https
|
|
|
1 |
+
|
2 |
+
#批量上传
|
3 |
+
import os
|
4 |
+
import requests
|
5 |
+
|
6 |
+
|
7 |
+
#->void
|
8 |
+
def upload_mask_to_space(baseUrl:str,mask_path:str,fake_headers:dict=None):
|
9 |
+
# 创建一个Session对象
|
10 |
+
session = requests.Session()
|
11 |
+
if fake_headers is not None:
|
12 |
+
session.headers = fake_headers
|
13 |
+
|
14 |
+
delete_url = baseUrl +"/deleteFiles"
|
15 |
+
directory_clear_list = ["manga", "manga1", "manga12", "output", "mp3_out", "mp4_out", "cover", "mask"]
|
16 |
+
for directory in directory_clear_list:
|
17 |
+
response = session.delete(delete_url, params={"directory": directory})
|
18 |
+
|
19 |
+
if response.status_code == 200:
|
20 |
+
print(response.text)
|
21 |
+
else:
|
22 |
+
print("请求失败,状态码:", response.status_code)
|
23 |
+
print("请求失败,状态码:", response.text)
|
24 |
+
|
25 |
+
upload_url = baseUrl +'/getOriginalMangaList'
|
26 |
+
# 获取当前目录的下的全部图片用于上传
|
27 |
+
img_path = mask_path
|
28 |
+
subdir_path = os.path.join(os.getcwd(), img_path)
|
29 |
+
image_files = []
|
30 |
+
for root, dirs, files in os.walk(subdir_path):
|
31 |
+
for file in files:
|
32 |
+
if file.endswith(".jpg") or file.endswith(".png"):
|
33 |
+
image_files.append(os.path.relpath(os.path.join(root, file)))
|
34 |
+
# 转换为上传格式并上传
|
35 |
+
upload_files = []
|
36 |
+
|
37 |
+
for image_path in image_files:
|
38 |
+
upload_files.append(("images", (image_path, open(image_path, "rb"), "image/jpeg")))
|
39 |
+
|
40 |
+
|
41 |
+
# 指定mask目录保存遮照图片结果
|
42 |
+
data = {
|
43 |
+
'save_path': "/mask"
|
44 |
+
}
|
45 |
+
|
46 |
+
response = session.post(upload_url, files=upload_files, params=data)
|
47 |
+
print(response.text)
|
48 |
+
|
49 |
+
|
50 |
+
if __name__ == '__main__':
|
51 |
+
#upload_mask_to_space(baseUrl='https://rogerxavier-moviepy-with-manga-test.hf.space',mask_path='mask')
|
52 |
upload_mask_to_space(baseUrl='https://rogerxavier-moviepy-with-manga-test.hf.space', mask_path='mask')#破案了,必须https
|