Skip to content

Instantly share code, notes, and snippets.

@kishida
kishida / ClipClient.java
Last active June 10, 2024 19:58
CLIPを使った画像検索
package imagesearchwithclip;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Arrays;
@kishida
kishida / clip_ui.py
Created June 7, 2024 14:09
日本語CLIPを使う分類
import gradio as gr
import io
import requests
from PIL import Image
import torch
from transformers import AutoImageProcessor, AutoModel, AutoTokenizer
HF_MODEL_PATH = 'line-corporation/clip-japanese-base'
tokenizer = AutoTokenizer.from_pretrained(HF_MODEL_PATH, trust_remote_code=True)
@kishida
kishida / Llama.java
Last active June 14, 2024 10:23
Llama2.java with FFM API
// based on https://github.com/karpathy/llama2.c/commit/411c5bd2db9a87e94e1bd1a6c7b7ca117adc4b01
// at Sep 14, 2023
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.io.UnsupportedEncodingException;
import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
@kishida
kishida / Calculator.java
Created April 15, 2024 05:54
calculator generated by CodeGemma 7B
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Calculator extends JFrame implements ActionListener {
private JTextField textField;
private JButton[] numberButtons;
private JButton[] operatorButtons;
private JButton clearButton;
@kishida
kishida / SevenGame.java
Last active October 2, 2024 09:46
7並べゲーム
/*
* to run, use Java 22 or later
* java --enable-preview --source 22 SevenGame.java
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.nio.charset.Charset;
import java.util.ArrayList;
@kishida
kishida / locus.java
Last active March 7, 2024 14:32
2点 A(-4,0), B(2,0)からの距離の比が2:1である点Pの軌跡を求める
#! /usr/bin/java --enable-preview --source 21
// ※Shebangで起動するときは拡張子をつけないか.java以外の拡張子にする
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.*;
import java.util.ArrayList;
@kishida
kishida / codeserver.py
Created February 6, 2024 05:01
Code inference server for HuggingFace VSCode
import uvicorn
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
import json
import logging
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "stabilityai/stable-code-3b"
@kishida
kishida / youri-ejje.py
Last active October 31, 2023 14:57
Youri 7B Instructionを使った翻訳システム
import torch
from transformers import AutoTokenizer
# model_name = "rinna/youri-7b-instruction-gptq"
model_name = "rinna/youri-7b-instruction"
load_in_8bit = True
tokenizer = AutoTokenizer.from_pretrained(model_name)
if "gptq" in model_name:
@kishida
kishida / llmchat.py
Created October 25, 2023 05:10
llm chat
# based on StableLM chat
# https://huggingface.co/spaces/stabilityai/stablelm-tuned-alpha-chat
import gradio as gr
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline, StoppingCriteria, StoppingCriteriaList, TextIteratorStreamer
import time
import numpy as np
from torch.nn import functional as F
import os
from threading import Thread
@kishida
kishida / ct2chat.py
Created October 25, 2023 05:09
ct2 chat
# based on StableLM chat
# https://huggingface.co/spaces/stabilityai/stablelm-tuned-alpha-chat
import gradio as gr
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, StoppingCriteria, StoppingCriteriaList
import ctranslate2
print(f"Starting to load the model to memory")