File size: 1,344 Bytes
17ec9cf
 
a85da31
 
 
 
ef09b89
 
 
17ec9cf
a85da31
 
ef09b89
 
 
 
 
a85da31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ef09b89
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
from transformers import AutoModelForImageTextToText, AutoProcessor
from pathlib import Path
import requests
import zipfile
import io
import os
from helpers import get_project_root

ROOT = get_project_root()

def setup_fonts():
    url = "https://github.com/googlefonts/noto-cjk/raw/main/Sans/SuperOTC/NotoSansCJK.ttc.zip"
    extract_to = ROOT / "backend" / "fonts"
    if Path(extract_to / "NotoSansCJK.ttc").exists():
        print(f"Font file exists at {extract_to}")
        return

    zip_path = os.path.join(extract_to, "NotoSansCJK.ttc.zip")

    # 2. Download the file
    print("Downloading Noto Sans CJK SuperOTC (this may take a minute)...")
    response = requests.get(url, stream=True)
    
    if response.status_code == 200:
        with open(zip_path, 'wb') as f:
            for chunk in response.iter_content(chunk_size=8192):
                f.write(chunk)
        print("Download complete.")

        # 3. Extract the ZIP
        print("Extracting...")
        with zipfile.ZipFile(zip_path, 'r') as zip_ref:
            zip_ref.extractall(extract_to)
        
        # 4. Cleanup the zip file to save space
        os.remove(zip_path)
        print(f"Done! Font extracted to {extract_to}")
    else:
        print(f"Failed to download. Status code: {response.status_code}")

if __name__ == "__main__":
    setup_fonts()