Manglify_Backend / setup.py
tonyliu404's picture
cleaned setup.py
f223266
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()