File size: 743 Bytes
532fbb0
0fcfd74
532fbb0
9684017
0fcfd74
532fbb0
9684017
0fcfd74
 
 
 
9684017
 
 
 
 
 
 
 
0fcfd74
9684017
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
from transformers import pipeline

# モデルの読み込み(初回は時間がかかります)
chatbot = pipeline("text-generation", model="rinna/japanese-gpt2-small", tokenizer="rinna/japanese-gpt2-small")

# 応答関数
def respond(message):
    response = chatbot(message, max_new_tokens=50, do_sample=True, top_k=50, temperature=0.7)
    return response[0]["generated_text"]

# Gradio インターフェース作成
iface = gr.Interface(
    fn=respond,
    inputs="text",
    outputs="text",
    title="日本語チャットボット",
    description="rinna 日本語GPT-2を使ったシンプルなチャットボット"
)

# スペース用に main チェック
if __name__ == "__main__":
    iface.launch()