Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline, AutoTokenizer
|
3 |
-
import spaces
|
4 |
@spaces.GPU
|
5 |
-
#
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
9 |
|
10 |
def generate_text(prompt, max_length):
|
11 |
result = generator(prompt, max_length=max_length, num_return_sequences=1)
|
@@ -14,8 +15,8 @@ def generate_text(prompt, max_length):
|
|
14 |
iface = gr.Interface(
|
15 |
fn=generate_text,
|
16 |
inputs=[
|
17 |
-
gr.Textbox(label="プロンプト"),
|
18 |
-
gr.Slider(minimum=10, maximum=
|
19 |
],
|
20 |
outputs=gr.Textbox(label="生成されたテキスト")
|
21 |
)
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline, AutoTokenizer
|
|
|
3 |
@spaces.GPU
|
4 |
+
# 日本語モデルを指定
|
5 |
+
model_name = "rinna/japanese-gpt2-medium"
|
6 |
+
|
7 |
+
# トークナイザーとパイプラインの設定
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
generator = pipeline('text-generation', model=model_name, tokenizer=tokenizer, device=-1)
|
10 |
|
11 |
def generate_text(prompt, max_length):
|
12 |
result = generator(prompt, max_length=max_length, num_return_sequences=1)
|
|
|
15 |
iface = gr.Interface(
|
16 |
fn=generate_text,
|
17 |
inputs=[
|
18 |
+
gr.Textbox(label="プロンプト", placeholder="ここに日本語のプロンプトを入力してください"),
|
19 |
+
gr.Slider(minimum=10, maximum=200, value=50, step=1, label="最大長")
|
20 |
],
|
21 |
outputs=gr.Textbox(label="生成されたテキスト")
|
22 |
)
|