Nyanpre commited on
Commit
00a595c
·
verified ·
1 Parent(s): 6c63350

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -6,6 +6,7 @@ from datetime import datetime, timedelta, timezone
6
  members = ["かほ", "さや", "こず", "るり", "めぐ", "つづ", "ぎん", "すず", "ひめ", "せら", "いず", "さち"]
7
 
8
  def get_personal_daily_oracle(device_id):
 
9
  seed_base = device_id if device_id else "default_fate"
10
  jst = timezone(timedelta(hours=9))
11
  today_str = datetime.now(jst).strftime("%Y-%m-%d")
@@ -25,20 +26,23 @@ def get_personal_daily_oracle(device_id):
25
 
26
  return oracle_html, peace_msg, gr.update(visible=True), gr.update(visible=True)
27
 
28
- # JS: 状態チェックと復元
29
  js_logic = """
30
  function(deviceId) {
 
31
  const lastDraw = localStorage.getItem('lastOracleDate');
32
  const lastPair = localStorage.getItem('lastPairText');
33
  const today = new Date().toLocaleDateString('ja-JP');
34
 
35
  if (lastDraw === today && lastPair) {
36
  alert("本日の神託は既に下されています。\\n明日の更新まで、今の思想を維持しなさい。");
37
- return [lastPair, "これにより、不毛なカップリング論争は終結しました。", { "visible": true, "__type__": "update" }, { "visible": true, "__type__": "update" }];
 
38
  }
39
 
40
  localStorage.setItem('lastOracleDate', today);
41
- return [null, null, null, null];
 
42
  }
43
  """
44
 
@@ -135,7 +139,7 @@ h1 {
135
  """
136
 
137
  with gr.Blocks(title="蓮ノ空聖書正典", css=custom_css, theme=gr.themes.Monochrome()) as demo:
138
- # 修正箇所: gr.State() gr.Textbox(visible=False) に変更
139
  device_id_storage = gr.Textbox(visible=False)
140
 
141
  demo.load(None, None, device_id_storage, js="""
 
6
  members = ["かほ", "さや", "こず", "るり", "めぐ", "つづ", "ぎん", "すず", "ひめ", "せら", "いず", "さち"]
7
 
8
  def get_personal_daily_oracle(device_id):
9
+ # IDが正しく渡れば、ここでシードが固定されます
10
  seed_base = device_id if device_id else "default_fate"
11
  jst = timezone(timedelta(hours=9))
12
  today_str = datetime.now(jst).strftime("%Y-%m-%d")
 
26
 
27
  return oracle_html, peace_msg, gr.update(visible=True), gr.update(visible=True)
28
 
29
+ # JS: 修正ポイント - localStorageからIDを直接取得してPythonに渡すように変更
30
  js_logic = """
31
  function(deviceId) {
32
+ const id = localStorage.getItem('cp_oracle_device_id') || "guest";
33
  const lastDraw = localStorage.getItem('lastOracleDate');
34
  const lastPair = localStorage.getItem('lastPairText');
35
  const today = new Date().toLocaleDateString('ja-JP');
36
 
37
  if (lastDraw === today && lastPair) {
38
  alert("本日の神託は既に下されています。\\n明日の更新まで、今の思想を維持しなさい。");
39
+ // [device_id, oracle_html, peace_msg, share_btn, result_display] の5要素を返す
40
+ return [id, lastPair, "これにより、不毛なカップリング論争は終結しました。", { "visible": true, "__type__": "update" }, { "visible": true, "__type__": "update" }];
41
  }
42
 
43
  localStorage.setItem('lastOracleDate', today);
44
+ // Pythonのfnを実行させるため、結果部分はnullで返しつつ、IDだけは確実に渡す
45
+ return [id, null, null, null, null];
46
  }
47
  """
48
 
 
139
  """
140
 
141
  with gr.Blocks(title="蓮ノ空聖書正典", css=custom_css, theme=gr.themes.Monochrome()) as demo:
142
+ # 修正箇所: StateをTextboxに変更(非表示)
143
  device_id_storage = gr.Textbox(visible=False)
144
 
145
  demo.load(None, None, device_id_storage, js="""