Update App2.py
Browse files
App2.py
CHANGED
|
@@ -85,41 +85,12 @@ def generate_response(message, history, temperature, top_p, top_k, max_output_to
|
|
| 85 |
history.append((message, response.text))
|
| 86 |
return "", history, history
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
THEMES = {
|
| 91 |
-
"Eternalstar": "Sakalti/Eternalstar",
|
| 92 |
-
"Mountainrainbow": "Sakalti/Mountainrainbow"
|
| 93 |
-
}
|
| 94 |
-
|
| 95 |
-
# 保存用ファイル
|
| 96 |
-
THEME_FILE = "theme_choice.txt"
|
| 97 |
-
|
| 98 |
-
def save_theme(choice):
|
| 99 |
-
with open(THEME_FILE, "w", encoding="utf-8") as f:
|
| 100 |
-
f.write(choice)
|
| 101 |
-
return f"テーマを「{choice}」に変更しました。再起動してください。"
|
| 102 |
-
|
| 103 |
-
# 前回の選択をロード
|
| 104 |
-
if os.path.exists(THEME_FILE):
|
| 105 |
-
with open(THEME_FILE, "r", encoding="utf-8") as f:
|
| 106 |
-
theme_choice = f.read().strip()
|
| 107 |
-
else:
|
| 108 |
-
theme_choice = "Eternalstar"
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
# ===== Gradio UI構築 =====
|
| 112 |
-
with gr.Blocks(theme=THEMES[theme_choice]) as demo:
|
| 113 |
gr.Markdown("## Gemini AIキャラクターチャット")
|
| 114 |
|
| 115 |
-
with gr.Row():
|
| 116 |
-
theme_dropdown = gr.Dropdown(choices=list(THEMES.keys()), value=theme_choice, label="テーマ切り替え")
|
| 117 |
-
theme_status = gr.Textbox(label="テーマステータス", interactive=False)
|
| 118 |
-
|
| 119 |
-
theme_dropdown.change(save_theme, inputs=[theme_dropdown], outputs=[theme_status])
|
| 120 |
-
|
| 121 |
with gr.Tab("チャット"):
|
| 122 |
-
chatbot = gr.Chatbot(
|
| 123 |
msg = gr.Textbox(placeholder="メッセージを入力...")
|
| 124 |
state = gr.State([])
|
| 125 |
system_prompt = gr.Textbox(label="キャラのシステムプロンプト", lines=4)
|
|
@@ -166,5 +137,4 @@ with gr.Blocks(theme=THEMES[theme_choice]) as demo:
|
|
| 166 |
character_list.change(load_prompt, inputs=[character_list], outputs=[system_prompt])
|
| 167 |
demo.load(refresh_characters, outputs=[character_list])
|
| 168 |
|
| 169 |
-
|
| 170 |
-
demo.launch()
|
|
|
|
| 85 |
history.append((message, response.text))
|
| 86 |
return "", history, history
|
| 87 |
|
| 88 |
+
# Gradio UIの構築
|
| 89 |
+
with gr.Blocks(theme='Sakalti/Eternalstar') as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
gr.Markdown("## Gemini AIキャラクターチャット")
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
with gr.Tab("チャット"):
|
| 93 |
+
chatbot = gr.Chatbot()
|
| 94 |
msg = gr.Textbox(placeholder="メッセージを入力...")
|
| 95 |
state = gr.State([])
|
| 96 |
system_prompt = gr.Textbox(label="キャラのシステムプロンプト", lines=4)
|
|
|
|
| 137 |
character_list.change(load_prompt, inputs=[character_list], outputs=[system_prompt])
|
| 138 |
demo.load(refresh_characters, outputs=[character_list])
|
| 139 |
|
| 140 |
+
demo.launch()
|
|
|