Files
church-translate/app/_probe-dot.mjs
T

23 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

import { pipeline, env } from '@huggingface/transformers';
import os from 'os'; import path from 'path';
env.allowLocalModels = false;
env.cacheDir = path.join(os.homedir(), 'Library/Application Support/Church Translate Models');
const pipe = await pipeline('translation', 'Xenova/nllb-200-distilled-600M', { dtype: 'fp32' });
const say = async (t, l) => {
const o = await pipe(t, { src_lang: 'eng_Latn', tgt_lang: l });
return (Array.isArray(o) ? o[0] : o).translation_text.trim();
};
const CASES = ['Peter.','John.','Matthew.','Noah.','Jesus.','Mary.','Moses.','Habakkuk.','Donald Trump.',
'Yes.','Okay.','Right.','Exactly.','Amen.','Watch this.','Come on.','Genesis.','Romans.',
'Simon Peter.','John the Baptist.'];
const LANGS = ['spa_Latn','por_Latn','fra_Latn'];
for (const lang of LANGS) {
console.log('\n=== ' + lang + ' ===');
console.log(' input'.padEnd(22) + 'WITH the period'.padEnd(34) + 'period STRIPPED before MT');
for (const t of CASES) {
const withDot = await say(t, lang);
const stripped = await say(t.replace(/[.!?]+$/, ''), lang);
console.log(' ' + t.padEnd(20) + withDot.slice(0, 32).padEnd(34) + stripped.slice(0, 32));
}
}