File size: 2,379 Bytes
8bea69a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import argparse
import shutil
from urllib.parse import urlparse
import json

import librosa
import numpy as np
from pathlib import Path

from gradio_client import Client, handle_file
import requests
import pandas as pd
from scipy.io import wavfile

from project_settings import project_path, environment


def get_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--audio_file",
        default="audio.xlsx",
        type=str,
    )
    parser.add_argument(
        "--audio_dir",
        default=(project_path / "temp/audio_trim/trimmed").as_posix(),
        type=str,
    )
    parser.add_argument(
        "--obs_secret_id",
        default=environment.get("obs_secret_id"),
        type=str,
    )
    parser.add_argument(
        "--obs_secret_key",
        default=environment.get("obs_secret_key"),
        type=str,
    )
    args = parser.parse_args()
    return args


client = Client("http://127.0.0.1:7861/")


def main():
    args = get_args()

    obs_kwargs = {
        "obs_supplier": "tencent",
        "url_prefix": "https://nxai-hk-1259196162.cos.ap-hongkong.myqcloud.com",
        "endpoint_url": "https://cos.ap-hongkong.myqcloud.com",
        "region": "ap-hongkong",
        "secret_id": args.obs_secret_id,
        "secret_key": args.obs_secret_key,
        "bucket": "nxai-hk-1259196162",
        # "debug": True
    }
    obs_kwargs = json.dumps(obs_kwargs, ensure_ascii=False, indent=4)
    print(obs_kwargs)

    audio_dir = Path(args.audio_dir)
    audio_dir.mkdir(parents=True, exist_ok=True)

    df = pd.read_excel(args.audio_file)

    for i, row in df.iterrows():
        name = row["name"]
        scene_id = row["scene_id"]
        audio_id = row["audio_id"]
        audio_url = row["audio_url"]

        schema = urlparse(audio_url)
        url_path = schema.path

        filename = audio_dir / url_path[1:]

        file_url, message = client.predict(
            filename=handle_file(filename.as_posix()),
            url_path=url_path[1:],
            obs_kwargs=obs_kwargs,
            api_name="/when_click_upload_to_obs"
        )
        print(filename.as_posix())
        print(f"file_url1: {audio_url}")
        print(f"file_url2: {file_url}")
        print(f"message: {message}")
        print("-" * 150)

    return


if __name__ == "__main__":
    main()