Skip to content

Instantly share code, notes, and snippets.

View celestialphineas's full-sized avatar
🐢
Slowly working on hanzi stuff

Celestial Phineas celestialphineas

🐢
Slowly working on hanzi stuff
View GitHub Profile
@celestialphineas
celestialphineas / pipeline_controlnet.py
Created January 9, 2024 02:00
One refactored version of huggingface/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet.py
# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@celestialphineas
celestialphineas / instantiate.sh
Created February 23, 2023 06:32
Instantiate an OTF variable font in CFF2 format to Type1 instances
tx -t1 -U 250 SourceHanSans-VF.otf > master1.pfb
tx -t1 -U 900 SourceHanSans-VF.otf > master1.pfb
@celestialphineas
celestialphineas / convert_diffusers_to_original_stable_diffusion.py
Created January 9, 2023 03:58
Modified Stable Diffusion .ckpt conversion script for Waifu Diffusion diffusers
# Script for converting a HF Diffusers saved pipeline to a Stable Diffusion checkpoint.
# *Only* converts the UNet, VAE, and Text Encoder.
# Does not convert optimizer state or any other thing.
import argparse
import os.path as osp
import re
import torch
@celestialphineas
celestialphineas / pix2pix-for-roman2italic.ipynb
Last active October 7, 2022 14:02
pix2pix-for-roman2italic.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@celestialphineas
celestialphineas / base.json
Created January 30, 2021 04:00
Generate otfcc font dump out of a folder of images
{
"head": {
"version": 1.0,
"fontRevision": 1.0,
"flags": {
"baselineAtY_0": true,
"alwaysUseIntegerSize": true
},
"unitsPerEm": 1000,
"macStyle": {},
@celestialphineas
celestialphineas / glyph_img.py
Created January 22, 2021 06:14
从字体文件输出字形
import os
import numpy as np
# 需要Pillow库
from PIL import Image, ImageDraw, ImageFont
# 需要fonttools库
from fontTools.ttLib import TTFont
# 从字体中返回一个字的图像(以numpy数组形式储存)
# 对大多数符合规范的字体,这个函数可以保证输出图像的边框正好是汉字的字身框
#(相当于稿纸上面的格子。一般比bounding box大一点,汉字在设计的时候不是顶着格的)
#!/usr/bin/env python3
# -*- encoding: utf8 -*-
import cairocffi as cairo
import numpy as np
# Adding the implicit on-points back to the contour
# The input is one single contour, not all of the glyph's contours
def regularize_quadratic_contour(contour):
result = []
if not contour[0]['on']:
#!/usr/bin/env python3
# -*- encoding: utf8 -*-
import os, json
import numpy as np
from PIL import Image, ImageDraw, ImageFont
def get_glyph_img(character, fontname,
pt = 1024, binarize = True,
descent_offset = True):
"""Get image of a certain glyph from the given font
@celestialphineas
celestialphineas / get_glyph_img.py
Created October 23, 2019 09:11
Get image of a certain glyph from the given font
#!/usr/bin/env python3
# -*- encoding: utf8 -*-
import os
import numpy as np
from PIL import Image, ImageDraw, ImageFont
dirname = os.path.dirname(__file__)
shs_cn_filename = os.path.join(dirname,
'../../data/fonts/SourceHanSansSC-ExtraLight.otf')
@celestialphineas
celestialphineas / tool_database_buildup.md
Last active April 3, 2019 18:13
Building up databases for common microbiome taxomy tools.

Mash sketch database

# Follow the Genomes Download FAQ (minus the 'complete' part): https://www.ncbi.nlm.nih.gov/genome/doc/ftpfaq/#allcomplete
wget -O assembly_summary.txt ftp://ftp.ncbi.nlm.nih.gov/genomes/refseq/archaea/assembly_summary.txt ftp://ftp.ncbi.nlm.nih.gov/genomes/refseq/bacteria/assembly_summary.txt
awk -F "\t" '$11=="latest"{print $20}' assembly_summary.txt > ftpdirpaths
awk 'BEGIN{FS=OFS="/";filesuffix="genomic.fna.gz"}{ftpdir=$0;asm=$10;file=asm"_"filesuffix;print ftpdir,file}' ftpdirpaths > ftpfilepaths
xargs -n 1 -P 32 wget -q < ftpfilepaths

# Double-check that all genomes were downloaded, please manually download missing file(s) – if any: