sirochild commited on
Commit
09b166c
·
verified ·
1 Parent(s): ddd58c3

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +19 -24
  2. style.css +160 -25
app.py CHANGED
@@ -23,13 +23,9 @@ genai.configure(api_key=GEMINI_API_KEY)
23
  gemini_model = genai.GenerativeModel('gemini-2.5-flash')
24
  groq_client = Groq(api_key=GROQ_API_KEY)
25
 
26
- print("日本語感情分析モデルをロード中...")
27
- try:
28
- sentiment_analyzer = pipeline("sentiment-analysis", model="koheiduck/bert-japanese-finetuned-sentiment")
29
- print("モデルのロード完了。")
30
- except Exception as e:
31
- sentiment_analyzer = None
32
- print(f"モデルのロードエラー: {e}")
33
 
34
  THEME_URLS = {
35
  "default": "https://cdn.pixabay.com/photo/2017/03/28/12/11/chairs-2181960_1280.jpg",
@@ -295,18 +291,21 @@ def get_relationship_stage(affection):
295
  return "ステージ4:最親密"
296
 
297
  def update_affection(message, affection):
298
- if not sentiment_analyzer: return affection
299
- try:
300
- result = sentiment_analyzer(message)[0]
301
- if result['label'] == 'positive': return min(100, affection + 5)
302
- if result['label'] == 'negative': return max(0, affection - 5)
303
- except Exception:
304
- return affection
305
- return affection
 
 
 
306
 
307
 
308
 
309
- async def respond(message, chat_history, affection, history, scene_params):
310
  new_affection = update_affection(message, affection)
311
  stage_name = get_relationship_stage(new_affection)
312
  current_theme = scene_params.get("theme", "default")
@@ -468,16 +467,12 @@ with gr.Blocks(css=custom_css, theme=custom_theme) as demo:
468
  [msg_input, chatbot, affection_gauge, stage_display, affection_state, history_state, scene_state, background_display],
469
  api_name="respond" # API名を指定して非同期処理を適切に処理
470
  )
471
- # 非同期関数として定義
472
- async def load_stage(affection):
473
  return get_relationship_stage(affection)
474
 
475
  demo.load(load_stage, affection_state, stage_display)
476
 
477
  if __name__ == "__main__":
478
- # 非同期処理の問題を解決するためのパラメータを追加
479
- demo.launch(
480
- prevent_thread_lock=True, # スレッドロックを防止
481
- show_error=True, # エラーを表示
482
- quiet=False # 詳細なログを出力
483
- )
 
23
  gemini_model = genai.GenerativeModel('gemini-2.5-flash')
24
  groq_client = Groq(api_key=GROQ_API_KEY)
25
 
26
+ # 日本語感情分析モデルの読み込みを無効化(パフォーマンス向上のため)
27
+ print("日本語感情分析モデルは無効化されています(パフォーマンス向上のため)")
28
+ sentiment_analyzer = None
 
 
 
 
29
 
30
  THEME_URLS = {
31
  "default": "https://cdn.pixabay.com/photo/2017/03/28/12/11/chairs-2181960_1280.jpg",
 
291
  return "ステージ4:最親密"
292
 
293
  def update_affection(message, affection):
294
+ # 感情分析モデルを使用せず、メッセージの長さに基づいて好感度を更新
295
+ # これにより、モデルの読み込みによるパフォーマンス問題を回避
296
+ message_length = len(message)
297
+
298
+ # 短いメッセージは好感度を下げる、長いメッセージは好感度を上げる
299
+ if message_length < 10:
300
+ return max(0, affection - 1) # 短いメッセージ
301
+ elif message_length > 30:
302
+ return min(100, affection + 3) # 長いメッセージ
303
+ else:
304
+ return min(100, affection + 1) # 普通のメッセージ
305
 
306
 
307
 
308
+ def respond(message, chat_history, affection, history, scene_params):
309
  new_affection = update_affection(message, affection)
310
  stage_name = get_relationship_stage(new_affection)
311
  current_theme = scene_params.get("theme", "default")
 
467
  [msg_input, chatbot, affection_gauge, stage_display, affection_state, history_state, scene_state, background_display],
468
  api_name="respond" # API名を指定して非同期処理を適切に処理
469
  )
470
+ # 通常の関数として定義
471
+ def load_stage(affection):
472
  return get_relationship_stage(affection)
473
 
474
  demo.load(load_stage, affection_state, stage_display)
475
 
476
  if __name__ == "__main__":
477
+ # シンプルな起動方法に戻す
478
+ demo.launch()
 
 
 
 
style.css CHANGED
@@ -125,30 +125,79 @@ body {
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
  /* ========================
@@ -156,6 +205,55 @@ button:hover {
156
  ======================== */
157
  .status-box {
158
  padding: 15px !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  }
160
 
161
  /* ========================
@@ -215,31 +313,68 @@ button:hover {
215
  チャットエリアなど(必要に応じて)
216
  ======================== */
217
  .gradio-container {
218
- position: relative; /* 背景をabsoluteで置くために */
219
- overflow: hidden;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
  }
 
125
  padding: 10px !important;
126
  }
127
 
128
+ /* 入力欄のスタイル - より目立つように */
129
+ textarea, input[type="text"], input[type="number"], .gradio-textbox {
130
+ background-color: rgba(255, 255, 255, 0.95) !important;
131
  border-radius: 8px !important;
132
+ border: 2px solid rgba(255, 100, 100, 0.5) !important;
133
+ padding: 12px !important;
134
+ font-size: 16px !important;
135
+ color: #333 !important;
136
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1) !important;
137
  backdrop-filter: blur(5px) !important;
138
  -webkit-backdrop-filter: blur(5px) !important;
139
+ margin-bottom: 10px !important;
140
+ min-height: 50px !important;
141
+ width: 100% !important;
142
+ display: block !important;
143
+ box-sizing: border-box !important;
144
  }
145
 
146
+ /* 入力欄のコンテナ */
147
+ .gradio-textbox {
148
  background-color: rgba(255, 255, 255, 0.8) !important;
149
+ padding: 10px !important;
150
+ border-radius: 10px !important;
151
+ margin-bottom: 15px !important;
152
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1) !important;
153
+ }
154
+
155
+ /* 入力欄のフォーカス時のスタイル */
156
+ textarea:focus, input[type="text"]:focus, input[type="number"]:focus {
157
+ border-color: rgba(255, 50, 50, 0.8) !important;
158
+ box-shadow: 0 0 8px rgba(255, 100, 100, 0.5) !important;
159
+ outline: none !important;
160
+ }
161
+
162
+ /* ボタンのスタイル - より目立つように */
163
+ button, .submit, button[type="submit"], .gradio-button {
164
+ background-color: rgba(255, 100, 100, 0.9) !important;
165
+ color: white !important;
166
  border-radius: 8px !important;
167
+ border: 1px solid rgba(200, 0, 0, 0.2) !important;
168
+ padding: 10px 20px !important;
169
+ font-weight: bold !important;
170
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2) !important;
171
+ margin: 5px !important;
172
+ height: auto !important;
173
+ min-height: 40px !important;
174
  transition: all 0.2s ease !important;
175
+ opacity: 1 !important;
176
+ visibility: visible !important;
177
+ display: block !important;
178
+ width: auto !important;
179
+ min-width: 100px !important;
180
+ font-size: 16px !important;
181
+ cursor: pointer !important;
182
+ z-index: 1000 !important;
183
+ position: relative !important;
184
  }
185
 
186
+ button:hover, .submit:hover, button[type="submit"]:hover, .gradio-button:hover {
187
+ background-color: rgba(255, 50, 50, 1.0) !important;
188
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3) !important;
189
+ transform: translateY(-2px) !important;
190
+ }
191
+
192
+ /* 送信ボタン特有のスタイル */
193
+ .submit, button[type="submit"] {
194
+ background-color: #ff4757 !important;
195
+ font-size: 18px !important;
196
+ padding: 12px 24px !important;
197
+ margin-top: 10px !important;
198
+ margin-bottom: 10px !important;
199
+ width: 100% !important;
200
+ max-width: 200px !important;
201
  }
202
 
203
  /* ========================
 
205
  ======================== */
206
  .status-box {
207
  padding: 15px !important;
208
+ background-color: rgba(255, 255, 255, 0.9) !important;
209
+ border-radius: 12px !important;
210
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1) !important;
211
+ margin-bottom: 15px !important;
212
+ }
213
+
214
+ /* スライダー(好感度バー)のスタイル */
215
+ .status-box input[type="range"], .gradio-slider input[type="range"] {
216
+ -webkit-appearance: none !important;
217
+ appearance: none !important;
218
+ width: 100% !important;
219
+ height: 20px !important;
220
+ border-radius: 10px !important;
221
+ background: linear-gradient(to right, #ff6b6b, #ff9e9e) !important;
222
+ outline: none !important;
223
+ opacity: 1 !important;
224
+ transition: opacity 0.2s !important;
225
+ margin: 15px 0 !important;
226
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2) !important;
227
+ border: 2px solid rgba(255, 255, 255, 0.5) !important;
228
+ }
229
+
230
+ .status-box input[type="range"]::-webkit-slider-thumb, .gradio-slider input[type="range"]::-webkit-slider-thumb {
231
+ -webkit-appearance: none !important;
232
+ appearance: none !important;
233
+ width: 30px !important;
234
+ height: 30px !important;
235
+ border-radius: 50% !important;
236
+ background: #ff4757 !important;
237
+ cursor: pointer !important;
238
+ box-shadow: 0 0 8px rgba(0, 0, 0, 0.3) !important;
239
+ border: 2px solid white !important;
240
+ }
241
+
242
+ /* スライダーのコンテナ */
243
+ .gradio-slider {
244
+ background-color: rgba(255, 255, 255, 0.8) !important;
245
+ padding: 15px !important;
246
+ border-radius: 10px !important;
247
+ margin-bottom: 15px !important;
248
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1) !important;
249
+ }
250
+
251
+ /* ラベルのスタイル */
252
+ .status-box label {
253
+ font-weight: bold !important;
254
+ color: #333 !important;
255
+ margin-bottom: 5px !important;
256
+ display: block !important;
257
  }
258
 
259
  /* ========================
 
313
  チャットエリアなど(必要に応じて)
314
  ======================== */
315
  .gradio-container {
316
+ position: relative !important; /* 背景をabsoluteで置くために */
317
+ overflow: hidden !important;
318
+ }
319
+
320
+ /* Gradio 5.0の特定のクラスに対するスタイル */
321
+ .gradio-row {
322
+ display: flex !important;
323
+ flex-wrap: wrap !important;
324
+ margin: 0 -10px !important;
325
+ }
326
+
327
+ .gradio-column {
328
+ padding: 0 10px !important;
329
+ box-sizing: border-box !important;
330
+ }
331
+
332
+ /* 入力エリアのコンテナ */
333
+ .input-container, .gradio-textbox-input {
334
+ background-color: rgba(255, 255, 255, 0.8) !important;
335
+ border-radius: 10px !important;
336
+ padding: 15px !important;
337
+ margin-bottom: 15px !important;
338
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1) !important;
339
+ }
340
+
341
+ /* 送信ボタンのコンテナ */
342
+ .submit-container {
343
+ display: flex !important;
344
+ justify-content: center !important;
345
+ margin-top: 10px !important;
346
  }
347
 
348
  .chatbot {
349
+ background-color: rgba(255, 255, 255, 0.7) !important;
350
  border-radius: 12px !important;
351
+ padding: 15px !important;
352
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1) !important;
353
+ margin-bottom: 20px !important;
354
+ min-height: 400px !important;
355
+ max-height: 600px !important;
356
+ overflow-y: auto !important;
357
  }
358
 
359
  /* チャットメッセージのスタイル */
360
  .chatbot > div > div > div {
361
+ background-color: rgba(255, 255, 255, 0.9) !important;
362
+ border-radius: 12px !important;
363
+ padding: 12px !important;
364
+ margin-bottom: 12px !important;
365
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
366
+ font-size: 16px !important;
367
+ line-height: 1.5 !important;
368
  }
369
 
370
  /* ユーザーメッセージ */
371
  .chatbot > div > div:nth-child(odd) > div {
372
+ background-color: rgba(230, 230, 255, 0.95) !important;
373
+ border-left: 4px solid #6c5ce7 !important;
374
  }
375
 
376
  /* ボットメッセージ */
377
  .chatbot > div > div:nth-child(even) > div {
378
+ background-color: rgba(255, 230, 230, 0.95) !important;
379
+ border-left: 4px solid #ff6b6b !important;
380
  }