sirochild commited on
Commit
5cfb951
·
verified ·
1 Parent(s): 027b5ee

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +12 -5
  2. style.css +26 -29
app.py CHANGED
@@ -148,20 +148,27 @@ def respond(message, chat_history, affection, history, scene_params):
148
  chat_history.append((message, bot_message))
149
  theme_name = final_scene_params.get("theme", "default")
150
 
151
- # JavaScriptを、data-theme属性を書き換えるように変更
152
  js_script = f"""
153
  <script>
154
  setTimeout(() => {{
155
- const body = document.body;
156
- console.log("Applying data-theme:", "{theme_name}");
157
- body.setAttribute('data-theme', 'theme-{theme_name}');
 
 
 
 
158
  }}, 50);
159
  </script>
160
  """
161
 
162
  return "", chat_history, new_affection, stage_name, new_affection, new_history, final_scene_params, js_script
163
 
164
- with gr.Blocks(css="style.css", theme=gr.themes.Soft(primary_hue="rose", secondary_hue="pink")) as demo:
 
 
 
165
  affection_state = gr.State(30)
166
  history_state = gr.State([])
167
  scene_state = gr.State(DEFAULT_SCENE_PARAMS)
 
148
  chat_history.append((message, bot_message))
149
  theme_name = final_scene_params.get("theme", "default")
150
 
151
+ # JavaScriptを、#main_containerのクラスを書き換えるように変更
152
  js_script = f"""
153
  <script>
154
  setTimeout(() => {{
155
+ const container = document.getElementById('main_container');
156
+ if(container){{
157
+ console.log("Applying theme to #main_container:", "{theme_name}");
158
+ const themes = ["theme-default", "theme-room_night", "theme-beach_sunset", "theme-festival_night", "theme-shrine_day", "theme-cafe_afternoon", "theme-aquarium_night"];
159
+ container.classList.remove(...themes);
160
+ container.classList.add("theme-{theme_name}");
161
+ }}
162
  }}, 50);
163
  </script>
164
  """
165
 
166
  return "", chat_history, new_affection, stage_name, new_affection, new_history, final_scene_params, js_script
167
 
168
+ # ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
169
+ # ★★★★★★★★★★★★★ 修正の中心部分 ★★★★★★★★★★★★★★
170
+ # ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
171
+ with gr.Blocks(css="style.css", theme=None, elem_id="main_container") as demo:
172
  affection_state = gr.State(30)
173
  history_state = gr.State([])
174
  scene_state = gr.State(DEFAULT_SCENE_PARAMS)
style.css CHANGED
@@ -1,41 +1,38 @@
1
- /* bodyタグの属性を直接ターゲットにする */
2
- body[data-theme="theme-default"] {
3
- --background-image: url('https://i.ibb.co/XzP6K2Y/room-day.png');
 
 
 
 
4
  }
5
- body[data-theme="theme-room_night"] {
6
- --background-image: url('https://i.ibb.co/d5m821p/room-night.png');
 
 
7
  }
8
- body[data-theme="theme-beach_sunset"] {
9
- --background-image: url('https://i.ibb.co/Q9r56s4/beach-sunset.png');
10
  }
11
- body[data-theme="theme-festival_night"] {
12
- --background-image: url('https://i.ibb.co/3zdJ6Bw/festival-night.png');
13
  }
14
- body[data-theme="theme-shrine_day"] {
15
- --background-image: url('https://i.ibb.co/L51Jd3x/shrine-day.png');
16
  }
17
- body[data-theme="theme-cafe_afternoon"] {
18
- --background-image: url('https://i.ibb.co/yQxG4vs/cafe-afternoon.png');
19
  }
20
- body[data-theme="theme-aquarium_night"] {
21
- --background-image: url('https://i.ibb.co/dK5r5rc/aquarium-night.png');
22
  }
23
-
24
- /* どのテーマでも背景画像を適用するための共通ルール */
25
- body {
26
- transition: background-image 1s ease-in-out;
27
- background-image: var(--background-image) !important;
28
- background-size: cover !important;
29
- background-position: center !important;
30
  }
31
 
32
  /* チャットウィンドウなどのスタイル */
33
- .gradio-chatbot .chatbot {
34
- background-color: rgba(255, 255, 255, 0.75) !important;
35
- backdrop-filter: blur(8px);
36
  border: 1px solid rgba(255, 255, 255, 0.2);
37
- }
38
- .gradio-textbox, .gradio-slider {
39
- background-color: rgba(255, 255, 255, 0.85) !important;
40
- border-radius: 10px !important;
41
  }
 
1
+ /* Gradioのルート要素(#main_container)を直接ターゲットにする */
2
+ #main_container {
3
+ /* テーマが適用されていない時のデフォルト背景 */
4
+ background-image: url('https://i.ibb.co/XzP6K2Y/room-day.png') !important;
5
+ background-size: cover !important;
6
+ background-position: center !important;
7
+ transition: background-image 1s ease-in-out;
8
  }
9
+
10
+ /* 各テーマの定義 */
11
+ #main_container.theme-default {
12
+ background-image: url('https://i.ibb.co/XzP6K2Y/room-day.png') !important;
13
  }
14
+ #main_container.theme-room_night {
15
+ background-image: url('https://i.ibb.co/d5m821p/room-night.png') !important;
16
  }
17
+ #main_container.theme-beach_sunset {
18
+ background-image: url('https://i.ibb.co/Q9r56s4/beach-sunset.png') !important;
19
  }
20
+ #main_container.theme-festival_night {
21
+ background-image: url('https://i.ibb.co/3zdJ6Bw/festival-night.png') !important;
22
  }
23
+ #main_container.theme-shrine_day {
24
+ background-image: url('https://i.ibb.co/L51Jd3x/shrine-day.png') !important;
25
  }
26
+ #main_container.theme-cafe_afternoon {
27
+ background-image: url('https://i.ibb.co/yQxG4vs/cafe-afternoon.png') !important;
28
  }
29
+ #main_container.theme-aquarium_night {
30
+ background-image: url('https://i.ibb.co/dK5r5rc/aquarium-night.png') !important;
 
 
 
 
 
31
  }
32
 
33
  /* チャットウィンドウなどのスタイル */
34
+ .gradio-chatbot .chatbot, .gradio-textbox, .gradio-slider, .gradio-markdown {
35
+ background-color: rgba(255, 255, 255, 0.8) !important;
36
+ backdrop-filter: blur(5px);
37
  border: 1px solid rgba(255, 255, 255, 0.2);
 
 
 
 
38
  }