Update app.py
Browse files
app.py
CHANGED
@@ -31,7 +31,6 @@ TOP_P = 0.95
|
|
31 |
def respond(message, history):
|
32 |
"""
|
33 |
チャットボットの応答を生成する関数
|
34 |
-
Gradio ChatInterfaceの標準形式に対応
|
35 |
"""
|
36 |
try:
|
37 |
# システムメッセージと会話履歴を含むプロンプトを構築
|
@@ -84,20 +83,35 @@ def respond(message, history):
|
|
84 |
except Exception as e:
|
85 |
return f"エラーが発生しました: {str(e)}"
|
86 |
|
87 |
-
# Gradio
|
88 |
-
|
89 |
-
respond,
|
90 |
title="🤖 Sarashina Chatbot",
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
if __name__ == "__main__":
|
103 |
demo.launch(
|
|
|
31 |
def respond(message, history):
|
32 |
"""
|
33 |
チャットボットの応答を生成する関数
|
|
|
34 |
"""
|
35 |
try:
|
36 |
# システムメッセージと会話履歴を含むプロンプトを構築
|
|
|
83 |
except Exception as e:
|
84 |
return f"エラーが発生しました: {str(e)}"
|
85 |
|
86 |
+
# Gradio Blocksを使用したチャットインターフェース
|
87 |
+
with gr.Blocks(
|
|
|
88 |
title="🤖 Sarashina Chatbot",
|
89 |
+
theme=gr.themes.Soft()
|
90 |
+
) as demo:
|
91 |
+
|
92 |
+
gr.Markdown("# 🤖 Sarashina Chatbot")
|
93 |
+
gr.Markdown("Sarashina2.2-3b-instruct モデルを使用した日本語チャットボットです。")
|
94 |
+
|
95 |
+
chatbot = gr.Chatbot(height=500)
|
96 |
+
msg = gr.Textbox(
|
97 |
+
label="メッセージを入力してください",
|
98 |
+
placeholder="こんにちは!何かお手伝いできることはありますか?",
|
99 |
+
lines=2
|
100 |
+
)
|
101 |
+
clear = gr.Button("会話をクリア")
|
102 |
+
|
103 |
+
def user(message, history):
|
104 |
+
return "", history + [[message, None]]
|
105 |
+
|
106 |
+
def bot(history):
|
107 |
+
history[-1][1] = respond(history[-1][0], history[:-1])
|
108 |
+
return history
|
109 |
+
|
110 |
+
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
111 |
+
bot, chatbot, chatbot
|
112 |
+
)
|
113 |
+
|
114 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
115 |
|
116 |
if __name__ == "__main__":
|
117 |
demo.launch(
|