rogerxavier commited on
Commit
6b71423
1 Parent(s): 7157ea6

Update task/_0上传遮罩.py

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