sirochild commited on
Commit
f07433f
·
verified ·
1 Parent(s): 186e5ca

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +63 -10
  2. style.css +57 -20
app.py CHANGED
@@ -176,19 +176,35 @@ def generate_dialogue_with_gemini(history, message, affection, stage_name, scene
176
  print(f"プロンプト長: {len(system_prompt)}")
177
 
178
  try:
 
 
 
179
  generation_config = genai.types.GenerationConfig(max_output_tokens=200, temperature=0.95)
180
  response = gemini_model.generate_content(system_prompt, generation_config=generation_config)
 
 
 
 
 
 
 
181
 
182
  if response.candidates and response.candidates[0].finish_reason in {1, 'STOP'}:
 
183
  return response.text.strip()
184
  else:
 
 
 
 
 
 
185
  # エラー情報をログファイルに記録(デバッグ用)
186
  import datetime
187
  with open("gemini_errors.log", "a") as f:
188
- finish_reason = response.candidates[0].finish_reason if response.candidates else 'N/A'
189
  f.write(f"時刻: {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
190
  f.write(f"応答生成が途中で終了しました。理由: {finish_reason}\n")
191
- f.write(f"Prompt Feedback: {response.prompt_feedback}\n")
192
 
193
  if hasattr(response, 'prompt_feedback') and response.prompt_feedback:
194
  for rating in response.prompt_feedback.safety_ratings:
@@ -239,17 +255,36 @@ def generate_dialogue_with_gemini(history, message, affection, stage_name, scene
239
  import random
240
  for key in scene_responses:
241
  if key in scene:
242
- return random.choice(scene_responses[key])
 
 
243
 
244
  # デフォルト応答
245
- return f"({scene}の様子を静かに見回して)ここか…悪くない場所かもな。"
 
 
246
  else:
247
- return "(……何か言おうとしたけど、言葉に詰まった)"
 
 
248
  except Exception as e:
249
  print(f"応答生成エラー(Gemini): {e}")
250
  import traceback
251
  traceback.print_exc() # スタックトレースを出力
252
- return "(ごめんなさい、ちょっと考えがまとまらない……)"
 
 
 
 
 
 
 
 
 
 
 
 
 
253
 
254
 
255
  # --- 他の関数とUI部分は変更ありません ---
@@ -320,15 +355,31 @@ def respond(message, chat_history, affection, history, scene_params):
320
 
321
  theme_name = final_scene_params.get("theme", "default")
322
 
323
- # より強力な背景更新用のHTMLを生成
324
  background_html = f'''
325
- <div class="background-container">
326
  <div class="chat-background {theme_name}"></div>
327
  </div>
328
  <style>
329
  .chat-background {{
330
  background-image: url({THEME_URLS.get(theme_name, THEME_URLS["default"])}) !important;
331
  }}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332
  </style>
333
  '''
334
 
@@ -346,13 +397,15 @@ custom_theme = gr.themes.Soft(
346
 
347
  # Gradio 5.xでのテーマカスタマイズ(最小限の設定のみ)
348
  try:
349
- # 透明度を持つ背景色を設定(Gradio 5.0で確実に動作するプロパティのみ)
350
- custom_theme = gr.themes.Soft(
351
  primary_hue="rose",
352
  secondary_hue="pink",
353
  neutral_hue="slate",
354
  spacing_size="sm",
355
  radius_size="lg",
 
 
356
  )
357
  except Exception as e:
358
  print(f"テーマカスタマイズエラー: {e}")
 
176
  print(f"プロンプト長: {len(system_prompt)}")
177
 
178
  try:
179
+ # デバッグ情報を追加
180
+ print(f"Gemini API呼び出し開始...")
181
+
182
  generation_config = genai.types.GenerationConfig(max_output_tokens=200, temperature=0.95)
183
  response = gemini_model.generate_content(system_prompt, generation_config=generation_config)
184
+
185
+ print(f"Gemini API呼び出し完了")
186
+ print(f"応答候補数: {len(response.candidates) if hasattr(response, 'candidates') and response.candidates else 'なし'}")
187
+
188
+ if hasattr(response, 'candidates') and response.candidates:
189
+ print(f"応答理由: {response.candidates[0].finish_reason}")
190
+ print(f"応答テキスト: {response.text if hasattr(response, 'text') else 'なし'}")
191
 
192
  if response.candidates and response.candidates[0].finish_reason in {1, 'STOP'}:
193
+ print(f"正常応答: {response.text.strip()}")
194
  return response.text.strip()
195
  else:
196
+ print(f"異常応答検出")
197
+ # エラー情報をコンソールに出力(デバッグ用)
198
+ finish_reason = response.candidates[0].finish_reason if hasattr(response, 'candidates') and response.candidates else 'N/A'
199
+ print(f"応答生成が途中で終了しました。理由: {finish_reason}")
200
+ print(f"Prompt Feedback: {response.prompt_feedback if hasattr(response, 'prompt_feedback') else 'なし'}")
201
+
202
  # エラー情報をログファイルに記録(デバッグ用)
203
  import datetime
204
  with open("gemini_errors.log", "a") as f:
 
205
  f.write(f"時刻: {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
206
  f.write(f"応答生成が途中で終了しました。理由: {finish_reason}\n")
207
+ f.write(f"Prompt Feedback: {response.prompt_feedback if hasattr(response, 'prompt_feedback') else 'なし'}\n")
208
 
209
  if hasattr(response, 'prompt_feedback') and response.prompt_feedback:
210
  for rating in response.prompt_feedback.safety_ratings:
 
255
  import random
256
  for key in scene_responses:
257
  if key in scene:
258
+ fallback = random.choice(scene_responses[key])
259
+ print(f"シーン '{key}' に対応するフォールバック応答: {fallback}")
260
+ return fallback
261
 
262
  # デフォルト応答
263
+ fallback = f"({scene}の様子を静かに見回して)ここか…悪くない場所かもな。"
264
+ print(f"デフォルトのシーンフォールバック応答: {fallback}")
265
+ return fallback
266
  else:
267
+ fallback = "(……何か言おうとしたけど、言葉に詰まった)"
268
+ print(f"一般的なフォールバック応答: {fallback}")
269
+ return fallback
270
  except Exception as e:
271
  print(f"応答生成エラー(Gemini): {e}")
272
  import traceback
273
  traceback.print_exc() # スタックトレースを出力
274
+
275
+ # エラー情報をログファイルに記録
276
+ import datetime
277
+ with open("gemini_errors.log", "a") as f:
278
+ f.write(f"時刻: {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
279
+ f.write(f"例外発生: {e}\n")
280
+ f.write(f"スタックトレース:\n")
281
+ import traceback
282
+ traceback.print_exc(file=f)
283
+ f.write("\n")
284
+
285
+ error_response = "(ごめんなさい、ちょっと考えがまとまらない……)"
286
+ print(f"例外発生時のフォールバック応答: {error_response}")
287
+ return error_response
288
 
289
 
290
  # --- 他の関数とUI部分は変更ありません ---
 
355
 
356
  theme_name = final_scene_params.get("theme", "default")
357
 
358
+ # より強力な背景更新用のHTMLを生成(z-indexを高くして常に表示されるように)
359
  background_html = f'''
360
+ <div class="background-container" id="bg-container-{theme_name}">
361
  <div class="chat-background {theme_name}"></div>
362
  </div>
363
  <style>
364
  .chat-background {{
365
  background-image: url({THEME_URLS.get(theme_name, THEME_URLS["default"])}) !important;
366
  }}
367
+
368
+ /* 背景コンテナのスタイルを強制的に適用 */
369
+ #bg-container-{theme_name} {{
370
+ position: fixed !important;
371
+ top: 0 !important;
372
+ left: 0 !important;
373
+ width: 100% !important;
374
+ height: 100% !important;
375
+ z-index: -1000 !important;
376
+ pointer-events: none !important;
377
+ }}
378
+
379
+ /* Gradioのコンテナを透明に */
380
+ .gradio-container, .gradio-container > div {{
381
+ background-color: transparent !important;
382
+ }}
383
  </style>
384
  '''
385
 
 
397
 
398
  # Gradio 5.xでのテーマカスタマイズ(最小限の設定のみ)
399
  try:
400
+ # 透明な背景色を設定(Gradio 5.0で確実に動作するプロパティのみ)
401
+ custom_theme = gr.themes.Base(
402
  primary_hue="rose",
403
  secondary_hue="pink",
404
  neutral_hue="slate",
405
  spacing_size="sm",
406
  radius_size="lg",
407
+ font=["Helvetica", "Arial", "sans-serif"],
408
+ font_mono=["Consolas", "Monaco", "monospace"],
409
  )
410
  except Exception as e:
411
  print(f"テーマカスタマイズエラー: {e}")
style.css CHANGED
@@ -15,26 +15,26 @@ body {
15
  z-index: 1 !important;
16
  }
17
 
18
- /* Gradio 5.0のブロックスタイル */
19
  .gradio-container > div > div {
20
- background-color: rgba(255, 255, 255, 0.85) !important;
21
  border-radius: 12px !important;
22
  margin-bottom: 16px !important;
23
  padding: 16px !important;
24
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important;
25
  }
26
 
27
  /* ========================
28
  背景画像設定
29
  ======================== */
30
- /* 背景画像コンテナ */
31
  .background-container {
32
  position: fixed !important;
33
  top: 0 !important;
34
  left: 0 !important;
35
  width: 100% !important;
36
  height: 100% !important;
37
- z-index: -100 !important; /* UIの後ろに配置 */
38
  pointer-events: none !important;
39
  overflow: hidden !important;
40
  }
@@ -48,8 +48,9 @@ body {
48
  height: 100% !important;
49
  background-size: cover !important;
50
  background-position: center !important;
51
- opacity: 0.2 !important; /* 薄く表示 */
52
- filter: blur(2px) !important; /* 少しぼかす */
 
53
  }
54
 
55
  /* 背景画像の上に半透明のオーバーレイを追加 */
@@ -60,23 +61,21 @@ body {
60
  left: 0 !important;
61
  width: 100% !important;
62
  height: 100% !important;
63
- background: linear-gradient(rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0.5)) !important;
64
- z-index: -99 !important;
65
  }
66
 
67
  /* ========================
68
  コンポーネント共通スタイル
69
  ======================== */
70
- /* グループ共通スタイル */
71
  .header-box, .chat-box, .input-box, .status-box, .footer-box {
72
- background-color: rgba(255, 255, 255, 0.85) !important;
73
  border-radius: 12px !important;
74
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important;
75
  padding: 15px !important;
76
  margin-bottom: 15px !important;
77
- backdrop-filter: blur(5px) !important;
78
- -webkit-backdrop-filter: blur(5px) !important;
79
- border: 1px solid rgba(255, 255, 255, 0.3) !important;
80
  }
81
 
82
  /* ========================
@@ -126,10 +125,30 @@ body {
126
  padding: 10px !important;
127
  }
128
 
129
- .input-box textarea {
 
 
130
  border-radius: 8px !important;
131
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
132
  padding: 10px !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  }
134
 
135
  /* ========================
@@ -201,8 +220,26 @@ body {
201
  }
202
 
203
  .chatbot {
204
- background-color: rgba(255, 255, 255, 0.8);
205
- backdrop-filter: blur(4px);
206
- border-radius: 12px;
207
- padding: 10px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  }
 
15
  z-index: 1 !important;
16
  }
17
 
18
+ /* Gradio 5.0のブロックスタイル - 完全に透明に */
19
  .gradio-container > div > div {
20
+ background-color: transparent !important;
21
  border-radius: 12px !important;
22
  margin-bottom: 16px !important;
23
  padding: 16px !important;
24
+ box-shadow: none !important;
25
  }
26
 
27
  /* ========================
28
  背景画像設定
29
  ======================== */
30
+ /* 背景画像コンテナ - 常に表示されるように */
31
  .background-container {
32
  position: fixed !important;
33
  top: 0 !important;
34
  left: 0 !important;
35
  width: 100% !important;
36
  height: 100% !important;
37
+ z-index: -1000 !important; /* 最背面に配置 */
38
  pointer-events: none !important;
39
  overflow: hidden !important;
40
  }
 
48
  height: 100% !important;
49
  background-size: cover !important;
50
  background-position: center !important;
51
+ opacity: 0.3 !important; /* 適度な透明度 */
52
+ filter: blur(1px) !important; /* 少しぼかす */
53
+ transition: all 0.5s ease !important; /* 背景切り替え時のアニメーション */
54
  }
55
 
56
  /* 背景画像の上に半透明のオーバーレイを追加 */
 
61
  left: 0 !important;
62
  width: 100% !important;
63
  height: 100% !important;
64
+ background: linear-gradient(rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.4)) !important;
65
+ z-index: -999 !important;
66
  }
67
 
68
  /* ========================
69
  コンポーネント共通スタイル
70
  ======================== */
71
+ /* グループ共通スタイル - 背景を透明に */
72
  .header-box, .chat-box, .input-box, .status-box, .footer-box {
73
+ background-color: transparent !important;
74
  border-radius: 12px !important;
75
+ box-shadow: none !important;
76
  padding: 15px !important;
77
  margin-bottom: 15px !important;
78
+ border: none !important;
 
 
79
  }
80
 
81
  /* ========================
 
125
  padding: 10px !important;
126
  }
127
 
128
+ /* 入力欄の背景を半透明に */
129
+ textarea, input[type="text"], input[type="number"] {
130
+ background-color: rgba(255, 255, 255, 0.8) !important;
131
  border-radius: 8px !important;
132
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
133
  padding: 10px !important;
134
+ backdrop-filter: blur(5px) !important;
135
+ -webkit-backdrop-filter: blur(5px) !important;
136
+ }
137
+
138
+ /* ボタンのスタイル */
139
+ button {
140
+ background-color: rgba(255, 255, 255, 0.8) !important;
141
+ border-radius: 8px !important;
142
+ border: 1px solid rgba(0, 0, 0, 0.1) !important;
143
+ padding: 8px 16px !important;
144
+ backdrop-filter: blur(5px) !important;
145
+ -webkit-backdrop-filter: blur(5px) !important;
146
+ transition: all 0.2s ease !important;
147
+ }
148
+
149
+ button:hover {
150
+ background-color: rgba(240, 240, 255, 0.9) !important;
151
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
152
  }
153
 
154
  /* ========================
 
220
  }
221
 
222
  .chatbot {
223
+ background-color: transparent !important;
224
+ border-radius: 12px !important;
225
+ padding: 10px !important;
226
+ }
227
+
228
+ /* チャットメッセージのスタイル */
229
+ .chatbot > div > div > div {
230
+ background-color: rgba(255, 255, 255, 0.8) !important;
231
+ border-radius: 8px !important;
232
+ padding: 10px !important;
233
+ margin-bottom: 8px !important;
234
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05) !important;
235
+ }
236
+
237
+ /* ユーザーメッセージ */
238
+ .chatbot > div > div:nth-child(odd) > div {
239
+ background-color: rgba(240, 240, 255, 0.9) !important;
240
+ }
241
+
242
+ /* ボットメッセージ */
243
+ .chatbot > div > div:nth-child(even) > div {
244
+ background-color: rgba(255, 240, 240, 0.9) !important;
245
  }