|
import os |
|
import gradio as gr |
|
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM |
|
|
|
|
|
os.environ["CUDA_VISIBLE_DEVICES"] = "" |
|
|
|
|
|
model_name = "sakanaai/evolllm-jp" |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
model = AutoModelForCausalLM.from_pretrained(model_name) |
|
generator = pipeline('text-generation', model=model, tokenizer=tokenizer, device=-1) |
|
|
|
def generate_text(prompt, max_length): |
|
result = generator(prompt, max_length=max_length, num_return_sequences=1) |
|
return result[0]['generated_text'] |
|
|
|
iface = gr.Interface( |
|
fn=generate_text, |
|
inputs=[ |
|
gr.Textbox(label="プロンプト", placeholder="ここに日本語のプロンプトを入力してください"), |
|
gr.Slider(minimum=10, maximum=200, value=50, step=1, label="最大長") |
|
], |
|
outputs=gr.Textbox(label="生成されたテキスト") |
|
) |
|
|
|
iface.launch() |