Hugging Faceãè¦ã¦ããããªããã°ã©ãã説æããã£ã½ãã¢ãã«ããã£ãã®ã§è©¦ãã¦ã¿ã¾ããã
ãã¨ãJavaã®UIããPythonãå¼ã³åºãç·´ç¿ã§ãããã
ã¨ããããããããªæãã§ã°ã©ãã®èª¬æããã¦ããã¾ããããã§ã¯ArrayãStreamã«å¯¾å¿ããæ°å¤ãèªã¿åã£ã¦ããã£ãããä¸çªéãæéãè¿ãã¦ããã£ãããã¦ã¾ãã
ã°ã©ã説æãããããã§ãã pic.twitter.com/zV4yfg85Ld
— ããã ൠ(K1S) (@kis) 2023å¹´4æ24æ¥
ã¾ãããã¾ããã£ããã®ã ããè¦ãã¦ããã®ã§ãã ãããã¡ããã¨çãã¦ããã¾ãããã
Hugging Faceãè¦ã¦ããããªããã°ã©ãã®èª¬æããã¦ãããããªGoogleç£ã¢ãã«ããã£ãã®ã§è©¦ãã¦ã¿ã¾ããã
https://huggingface.co/google/matcha-chartqa
ã¢ãã«ã®å¤æã¨ããå¿ è¦ãããªãã ãã©ãybelkadaããã®ã¨ããã«ç½®ãã¦ããã®ã§ããã使ãã¾ãã
import sys from transformers import Pix2StructForConditionalGeneration, Pix2StructProcessor from PIL import Image model_name = "ybelkada/matcha-chartqa" model = Pix2StructForConditionalGeneration.from_pretrained(model_name) model.to("cuda:0") processor = Pix2StructProcessor.from_pretrained(model_name) while True: path = input() q = input() image = Image.open(path) inputs = processor(images=image, text=q, return_tensors="pt").to(0) predictions = model.generate(**inputs, max_new_tokens=512) print(processor.decode(predictions[0], skip_special_tokens=True))
ãã¨ã¯Javaã§Pythonã®ããã»ã¹ãèµ·å
ProcessBuilder pb = new ProcessBuilder(PYTHON_PATH, SCRIPT_PATH); pb.redirectErrorStream(false); Process p = pb.start(); OutputStream os = p.getOutputStream(); pyIn = new PrintWriter(os); InputStream is = p.getInputStream(); pyOut = new BufferedReader(new InputStreamReader(is));
ãã¿ã³ãæ¼ããã¨ãã«å ¥åã渡ãã¦åãåã£ããã®ã表示ããã¾ãã
pyIn.println(path.getAbsolutePath());
pyIn.println(question);
pyIn.flush();
return pyOut.readLine();
GPUã¡ã¢ãªã¯2.5GBãããã
ã³ã¼ãã¯ããã§ãã
https://gist.github.com/kishida/ce97494f98871f0f84c8f6c6b4553886