File size: 1,401 Bytes
fa0cf56
 
70d62e6
fa0cf56
70d62e6
fa0cf56
 
 
 
 
 
 
 
 
 
 
 
4b19472
70d62e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fa0cf56
 
 
 
 
 
 
 
 
 
 
 
8878a5a
fa0cf56
 
 
4b19472
fa0cf56
 
 
 
4b19472
fa0cf56
 
 
 
 
 
 
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
#!/usr/bin/env python3

import os
from pathlib import Path
from typing import List

BASE_URL = "https://huggingface.co/csukuangfj/k2/resolve/main/"


def generate_url(files: List[str]) -> List[str]:
    ans = []
    base = BASE_URL
    for f in files:
        ans.append(base + str(f))
    return ans


def get_all_files(d: str, suffix: str) -> List[str]:
    if "*" in suffix:
        suffix = suffix.split(".")[-1]

    d_list = d

    if isinstance(d_list, str):
        d_list = [d_list]

    ss = []
    for d in d_list:
        for root, _, files in os.walk(d):
            for f in files:
                if f.endswith(suffix):
                    ss.append(os.path.join(root, f))

    return sorted(ss, reverse=True)


def to_markdown(urls: List[str]) -> List[str]:
    ans = []
    for url in urls:
        name = url.rsplit("/", maxsplit=1)[1]
        ans.append(f"[{name}]({url})")
    return ans


def to_file(filename: str, md: List[str]):
    with open(filename, "w") as f:
        f.write("<br/>\n".join(md))


def main():
    cpu = get_all_files("cpu", suffix="*.whl")
    cpu_wheels = generate_url(cpu)
    cpu_wheels = to_markdown(cpu_wheels)
    to_file("cpu.md", cpu_wheels)

    cuda = get_all_files("cuda", suffix="*.whl")
    cuda_wheels = generate_url(cuda)
    cuda_wheels = to_markdown(cuda_wheels)
    to_file("cuda.md", cuda_wheels)


if __name__ == "__main__":
    main()