Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,29 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from transformers import pipeline
|
3 |
import os
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
|
8 |
-
#
|
9 |
-
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
result
|
14 |
-
return result['generated_text']
|
15 |
|
16 |
-
# Gradioインターフェースの設定
|
17 |
iface = gr.Interface(
|
18 |
fn=generate_text,
|
19 |
-
inputs=
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
23 |
)
|
24 |
|
25 |
-
|
26 |
-
iface.launch()
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
4 |
+
|
5 |
+
# CUDAを無効にする
|
6 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = ""
|
7 |
|
8 |
+
# 日本語モデルを指定
|
9 |
+
model_name = "sakanaai/evolllm-jp" # Sakana AIのモデル名を指定
|
10 |
|
11 |
+
# トークナイザーとパイプラインの設定
|
12 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
13 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
14 |
+
generator = pipeline('text-generation', model=model, tokenizer=tokenizer, device=-1) # device=-1はCPUを使用する設定
|
15 |
|
16 |
+
def generate_text(prompt, max_length):
|
17 |
+
result = generator(prompt, max_length=max_length, num_return_sequences=1)
|
18 |
+
return result[0]['generated_text']
|
|
|
19 |
|
|
|
20 |
iface = gr.Interface(
|
21 |
fn=generate_text,
|
22 |
+
inputs=[
|
23 |
+
gr.Textbox(label="プロンプト", placeholder="ここに日本語のプロンプトを入力してください"),
|
24 |
+
gr.Slider(minimum=10, maximum=200, value=50, step=1, label="最大長")
|
25 |
+
],
|
26 |
+
outputs=gr.Textbox(label="生成されたテキスト")
|
27 |
)
|
28 |
|
29 |
+
iface.launch()
|
|