File size: 1,704 Bytes
7d4961d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

#批量上传
import os
import requests
#->void
def upload_mask_to_space(baseUrl:str,mask_path:str):
    delete_url = baseUrl +"/deleteFiles"
    directory_clear_list = ["manga", "manga1", "manga12", "output", "mp3_out", "mp4_out", "cover", "mask"]
    for directory in directory_clear_list:
        response = requests.delete(delete_url, params={"directory": directory})

        if response.status_code == 200:
            print(response.text)
        else:
            print("请求失败,状态码:", response.status_code)
            print("请求失败,状态码:", response.text)

    upload_url = baseUrl +'/getOriginalMangaList'
    # 获取当前目录的下的全部图片用于上传
    img_path = mask_path
    subdir_path = os.path.join(os.getcwd(), img_path)
    image_files = []
    for root, dirs, files in os.walk(subdir_path):
        for file in files:
            if file.endswith(".jpg") or file.endswith(".png"):
                image_files.append(os.path.relpath(os.path.join(root, file)))
    # 转换为上传格式并上传
    upload_files = []

    for image_path in image_files:
        upload_files.append(("images", (image_path, open(image_path, "rb"), "image/jpeg")))


    # 指定mask目录保存遮照图片结果
    data = {
        'save_path': "/mask"
    }
    response = requests.post(upload_url, files=upload_files, params=data)
    print(response.text)
if __name__ == '__main__':
   #upload_mask_to_space(baseUrl='https://rogerxavier-moviepy-with-manga-test.hf.space',mask_path='mask')
   upload_mask_to_space(baseUrl='https://rogerxavier-moviepy-with-manga-test.hf.space', mask_path='mask')#破案了,必须https