okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
0479b72e9
main
1#!/usr/bin/env python3 2"""Runs one strata-vision reader over pictures and keeps the embeddings: <out dir>/<picture name>.sve. 3 4python3 make_sve.py --helper <strata-vision> --mmproj <mmproj.gguf> --model <text model or x> --tower own|mtmd [--gpu] [--max-tokens 1024] [--threads N] 5[--env NAME=VALUE ...] --out <dir> <image> [<image> ...] 6Used to make the embedding sets the answers runs read (for instance our tower with STRATA_VIT_REF_ROUND=1). Standard library only. 7""" 8import argparse 9import os 10import subprocess 11import sys 12 13 14def main (): 15ap = argparse .ArgumentParser () 16ap .add_argument ("--helper" ,required = True ) 17ap .add_argument ("--mmproj" ,required = True ) 18ap .add_argument ("--model" ,default = "x" ) 19ap .add_argument ("--tower" ,default = "own" ) 20ap .add_argument ("--gpu" ,action = "store_true" ) 21ap .add_argument ("--max-tokens" ,type = int ,default = 1024 ) 22ap .add_argument ("--threads" ,type = int ,default = 0 ) 23ap .add_argument ("--env" ,action = "append" ,default = []) 24ap .add_argument ("--out" ,required = True ) 25ap .add_argument ("images" ,nargs = "+" ) 26a = ap .parse_args () 27os .makedirs (a .out ,exist_ok = True ) 28args = [a .helper ,"--mmproj" ,a .mmproj ,"--model" ,a .model ,"--tower" ,a .tower ,"--max-tokens" ,str (a .max_tokens )] 29if a .gpu : 30args .append ("--gpu" ) 31if a .threads and not a .gpu : 32args += ["--threads" ,str (a .threads )] 33env = dict (os .environ ) 34for kv in a .env : 35k ,_ ,v = kv .partition ("=" ) 36env [k ]= v 37p = subprocess .Popen (args ,stdin = subprocess .PIPE ,stdout = subprocess .PIPE ,stderr = subprocess .DEVNULL ,text = True ,env = env ) 38if not p .stdout .readline ().startswith ("READY" ): 39raise SystemExit ("reader did not start" ) 40bad = 0 41for img in a .images : 42out = os .path .join (a .out ,os .path .basename (img )+ ".sve" ) 43p .stdin .write ("ENC %s %s\n" % (os .path .abspath (img ),out )) 44p .stdin .flush () 45r = p .stdout .readline ().strip () 46"%-26s %s" % (os .path .basename (img ),r ),flush = True ) 47bad += 0 if r .startswith ("OK" )else 1 48p .stdin .write ("QUIT\n" ) 49p .stdin .flush () 50p .wait (timeout = 60 ) 51return 1 if bad else 0 52 53 54if __name__ == "__main__" : 55sys .exit (main ())