Skip to content

Instantly share code, notes, and snippets.

@advanceboy
advanceboy / rinna_gradio_chat.py
Last active August 9, 2024 07:23
rinna/japanese-gpt-neox-3.6b-instruction-sft もとい rinna/japanese-gpt-neox-3.6b-instruction-ppo と gradio を使ったチャット UI のサンプル実装です。 transformers.TextIteratorStreamer API を利用して、 ChatGPT のように生成したテキストを少しずつ出力し、gradio の UI でユーザーに表示させています。
# coding=utf-8
# License: CC0
"""
rinna/japanese-gpt-neox-3.6b-instruction-ppo と gradio を使ったチャット UI のサンプル実装です。
-> https://huggingface.co/rinna/japanese-gpt-neox-3.6b-instruction-ppo
transformers.TextIteratorStreamer API を利用して、 ChatGPT のように生成したテキストを少しずつ表示し、ユーザー体験を向上させています。
-> https://huggingface.co/docs/transformers/v4.29.1/en/internal/generation_utils#transformers.TextIteratorStreamer
streamer クラスの API は開発中のため、近い将来互換性がなくなる可能性があります。
@advanceboy
advanceboy / intercept-response.js
Created December 3, 2023 17:22
ブラウザ操作中の通信の内容をローカルファイルに自動で保存する
// Run the Chrome Devtools Protocol via puppeteer-core to automatically save the contents of network communications to a local file.
const puppeteer = require('puppeteer-core');
const fs = require('fs/promises');
const path = require('path');
const [nodePath, scriptPath, ...args] = process.argv;
const how2useMsg = " node intercept-requests.js outputDir [urlPattern] [matchRegExp]\n outputDir: Output Directory\n urlPattern: If specified, only URLs matched with wildcards will be fetched. see https://chromedevtools.github.io/devtools-protocol/tot/Fetch/#type-RequestPattern . It's better to specify this for performance reasons.\n matchRegExp: If specified, only URLs that match regular expressions will be saved.";
if (args.length < 1) {
console.log(`one or more arguments are required.\n\n${how2useMsg}`);
process.exit(1);
@advanceboy
advanceboy / copy-formatted-title-and-url-bookmarklet.js
Last active February 25, 2024 15:45
ブラウザのタイトルや URL をコピーするブックマークレット
// タイトルをコピーするモーダルダイアログを表示させる
(() => {
// フレームを使っている場合は、先頭のフレームのドキュメントを対象とする
let d = "FRAMESET" === top.document.body.tagName ? top.frames[0].document : document, g = k => d.getElementById(k), c = d.createElement("div"), i = "modalBMId_key";
// モーダルダイアログを表示させるエレメントの作成
c.innerHTML = `<div id=${i}m style="position:fixed;width:100%;height:100%;top:0;left:0;text-align:center;background:rgba(0,0,0,.5);padding:16px 20px;z-index:2147483640"><div style="display:inline-block;background:#fff"><div style="padding:8px"><div id=${i}b></div><div><label for=${i}i style="color:#000">copied:</label><input id=${i}i style="width:400px" readonly/></div></div></div></div>`;
let m = g(i + "m");
if (!m) {
d.body.prepend(c.firstChild);
// 変換テンプレートの宣言
@advanceboy
advanceboy / .README-for-cloud-init-of-raspi
Last active April 25, 2024 15:13
Ubuntu Server for Raspberry Pi の cloud-init 初期化スクリプトの書き換え例です
Ubuntu Server for Raspberry Pi の cloud-init 初期化スクリプトの書き換え例です
@advanceboy
advanceboy / .gitignore
Last active December 17, 2024 14:19
`rawinput-touchpad.rs` dump RawInput HID reports of touchpad
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt