Upload 2 files
Browse files- app.py +65 -4
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -314,19 +314,80 @@ def respond(message, chat_history, affection, history, scene_params):
|
|
| 314 |
new_history = history + [(message, bot_message)]
|
| 315 |
chat_history.append((message, bot_message))
|
| 316 |
theme_name = final_scene_params.get("theme", "default")
|
| 317 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
return "", chat_history, new_affection, stage_name, new_affection, new_history, final_scene_params, background_html
|
| 319 |
|
| 320 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
scene_state = gr.State(DEFAULT_SCENE_PARAMS)
|
| 322 |
affection_state = gr.State(30)
|
| 323 |
history_state = gr.State([])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
gr.Markdown("# 麻理チャット")
|
| 325 |
with gr.Row():
|
| 326 |
with gr.Column(scale=2):
|
| 327 |
with gr.Column(elem_id="chat_container"):
|
| 328 |
-
|
| 329 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
msg_input = gr.Textbox(label="あなたのメッセージ", placeholder="「水族館はどう?」と聞いた後、「いいね、行こう!」のように返してみてください", scale=5, show_label=False)
|
| 331 |
with gr.Column(scale=1):
|
| 332 |
stage_display = gr.Textbox(label="現在の関係ステージ", interactive=False, value=get_relationship_stage(30))
|
|
|
|
| 314 |
new_history = history + [(message, bot_message)]
|
| 315 |
chat_history.append((message, bot_message))
|
| 316 |
theme_name = final_scene_params.get("theme", "default")
|
| 317 |
+
|
| 318 |
+
# より強力な背景更新用のHTMLを生成
|
| 319 |
+
background_html = f'''
|
| 320 |
+
<div class="chat-background {theme_name}"></div>
|
| 321 |
+
<style>
|
| 322 |
+
.chat-background {{
|
| 323 |
+
background-image: url({THEME_URLS.get(theme_name, THEME_URLS["default"])}) !important;
|
| 324 |
+
}}
|
| 325 |
+
</style>
|
| 326 |
+
'''
|
| 327 |
+
|
| 328 |
return "", chat_history, new_affection, stage_name, new_affection, new_history, final_scene_params, background_html
|
| 329 |
|
| 330 |
+
# カスタムCSSを読み込む
|
| 331 |
+
with open("style.css", "r") as f:
|
| 332 |
+
custom_css = f.read()
|
| 333 |
+
|
| 334 |
+
# Gradio 5.x対応のテーマ設定
|
| 335 |
+
try:
|
| 336 |
+
# Gradio 5.x
|
| 337 |
+
custom_theme = gr.themes.Soft(
|
| 338 |
+
primary_hue="rose",
|
| 339 |
+
secondary_hue="pink",
|
| 340 |
+
)
|
| 341 |
+
# Gradio 5.xでは.setメソッドが廃止されているため、直接プロパティを設定
|
| 342 |
+
custom_theme.body_background_fill = "rgba(255, 255, 255, 0.2)"
|
| 343 |
+
custom_theme.block_background_fill = "rgba(255, 255, 255, 0.1)"
|
| 344 |
+
custom_theme.block_label_background_fill = "rgba(255, 255, 255, 0.2)"
|
| 345 |
+
custom_theme.input_background_fill = "rgba(255, 255, 255, 0.6)"
|
| 346 |
+
custom_theme.chatbot_code_background_fill = "rgba(0, 0, 0, 0.1)"
|
| 347 |
+
except AttributeError:
|
| 348 |
+
# Gradio 3.x/4.x
|
| 349 |
+
custom_theme = gr.themes.Soft(
|
| 350 |
+
primary_hue="rose",
|
| 351 |
+
secondary_hue="pink",
|
| 352 |
+
).set(
|
| 353 |
+
body_background_fill="rgba(255, 255, 255, 0.2)",
|
| 354 |
+
block_background_fill="rgba(255, 255, 255, 0.1)",
|
| 355 |
+
block_label_background_fill="rgba(255, 255, 255, 0.2)",
|
| 356 |
+
input_background_fill="rgba(255, 255, 255, 0.6)",
|
| 357 |
+
chatbot_code_background_fill="rgba(0, 0, 0, 0.1)",
|
| 358 |
+
)
|
| 359 |
+
|
| 360 |
+
with gr.Blocks(css=custom_css, theme=custom_theme) as demo:
|
| 361 |
scene_state = gr.State(DEFAULT_SCENE_PARAMS)
|
| 362 |
affection_state = gr.State(30)
|
| 363 |
history_state = gr.State([])
|
| 364 |
+
|
| 365 |
+
# 背景コンテナを先に配置
|
| 366 |
+
background_display = gr.HTML(f'<div class="chat-background {DEFAULT_SCENE_PARAMS["theme"]}"></div>', elem_id="background_container")
|
| 367 |
+
|
| 368 |
gr.Markdown("# 麻理チャット")
|
| 369 |
with gr.Row():
|
| 370 |
with gr.Column(scale=2):
|
| 371 |
with gr.Column(elem_id="chat_container"):
|
| 372 |
+
# Gradio 5.x対応のChatbot設定
|
| 373 |
+
try:
|
| 374 |
+
# Gradio 5.x
|
| 375 |
+
chatbot = gr.Chatbot(
|
| 376 |
+
label="麻理との会話",
|
| 377 |
+
elem_id="chat_area",
|
| 378 |
+
show_label=False,
|
| 379 |
+
# Gradio 5.xでは bubble_full_width が廃止され、container が使用される
|
| 380 |
+
container=False,
|
| 381 |
+
avatar_images=["👤", "🤖"]
|
| 382 |
+
)
|
| 383 |
+
except TypeError:
|
| 384 |
+
# Gradio 3.x/4.x
|
| 385 |
+
chatbot = gr.Chatbot(
|
| 386 |
+
label="麻理との会話",
|
| 387 |
+
bubble_full_width=False,
|
| 388 |
+
elem_id="chat_area",
|
| 389 |
+
show_label=False
|
| 390 |
+
)
|
| 391 |
msg_input = gr.Textbox(label="あなたのメッセージ", placeholder="「水族館はどう?」と聞いた後、「いいね、行こう!」のように返してみてください", scale=5, show_label=False)
|
| 392 |
with gr.Column(scale=1):
|
| 393 |
stage_display = gr.Textbox(label="現在の関係ステージ", interactive=False, value=get_relationship_stage(30))
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
gradio
|
| 2 |
google-generativeai
|
| 3 |
groq
|
| 4 |
python-dotenv
|
|
|
|
| 1 |
+
gradio>=5.0.0
|
| 2 |
google-generativeai
|
| 3 |
groq
|
| 4 |
python-dotenv
|