atxorochi
Add application file
9684017
raw
history blame contribute delete
743 Bytes
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()