Nyanpre commited on
Commit
333e10a
·
verified ·
1 Parent(s): fbe7689

Update apppp.txt

Browse files
Files changed (1) hide show
  1. apppp.txt +32 -85
apppp.txt CHANGED
@@ -6,7 +6,6 @@ from datetime import datetime, timedelta, timezone
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")
@@ -24,9 +23,10 @@ def get_personal_daily_oracle(device_id):
24
  )
25
  peace_msg = "これにより、不毛なカップリング論争は終結しました。"
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";
@@ -36,31 +36,28 @@ function(deviceId) {
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
 
49
  # JS: 結果の保存
50
  js_save_result = """
51
- function(oracleHtml, peaceMsg, shareBtn, resultBox) {
52
  if (oracleHtml && oracleHtml.includes("本日の神託")) {
53
  localStorage.setItem('lastPairText', oracleHtml);
54
  }
55
  }
56
  """
57
 
58
- # JS: Bluesky投稿(URLの前に改行を入れてリン認識を改善)
59
- js_share_bluesky = """
60
  function() {
61
  const pairRawEl = document.getElementById('pair-raw');
62
  let pairName = "";
63
-
64
  if (pairRawEl) {
65
  pairName = pairRawEl.innerText;
66
  } else {
@@ -68,91 +65,40 @@ function() {
68
  const match = lastPair.match(/>([^<]{4,})<\\/div>$/);
69
  pairName = match ? match[1] : "運命";
70
  }
71
-
72
  const currentUrl = window.location.href;
73
- // URLの直前に改行2つ入れることで、SNS側がURLを独立たリンクとし認識しやすくなります
74
- const text = `私は「${pairName}」を信仰しています。\\n\\n蓮ノ空聖書正典:\\n${currentUrl}`;
75
- const intentUrl = `https://bsky.app/intent/compose?text=${encodeURIComponent(text)}`;
76
- window.open(intentUrl, '_blank');
77
  }
78
  """
79
 
 
 
 
 
80
  custom_css = """
81
  .gradio-container { max-width: 600px !important; text-align: center !important; }
 
 
 
82
 
83
- /* 1. 最上部の空白を45pxに設定 */
84
- .center-content {
85
- display: flex !important;
86
- flex-direction: column !important;
87
- align-items: center !important;
88
- padding-top: 45px !important;
89
- }
90
-
91
- /* 2. タイトルと教義の間を-5px */
92
- h1 {
93
- margin-top: 0px !important;
94
- margin-bottom: -5px !important;
95
- font-size: 32px !important;
96
- }
97
-
98
- /* 3. 教義と結果の間を-5px */
99
- #doctrine {
100
- font-size: 1.5em !important;
101
- line-height: 1.4 !important;
102
- font-weight: bold !important;
103
- margin-bottom: -5px !important;
104
- text-align: center !important;
105
- }
106
-
107
- /* 4. 結果ボックス(基本:ライトモード) */
108
  #oracle-box {
109
- color: #000 !important;
110
- background: #fff !important;
111
- border: 4px solid #000 !important;
112
- padding: 25px 10px !important;
113
- line-height: 1.1 !important;
114
- min-height: 130px !important;
115
- display: flex !important;
116
- flex-direction: column !important;
117
- justify-content: center !important;
118
  margin: 0px auto -5px auto !important;
119
  }
 
120
 
121
- /* ★ダークモード時の色指定を追加 */
122
- .dark #oracle-box {
123
- color: #fff !important;
124
- background: #000 !important;
125
- border: 4px solid #fff !important;
126
- }
127
-
128
- /* 5. 終結文とボタンの間を-5px */
129
- #peace-msg {
130
- font-size: 20px !important;
131
- font-weight: bold !important;
132
- color: #d63031 !important;
133
- margin: 0px auto -5px auto !important;
134
- }
135
 
136
- /* 6. ボタン同士の間を-5px */
137
- .action-btn {
138
- font-size: 26px !important;
139
- font-weight: bold !important;
140
- height: 70px !important;
141
- width: 320px !important;
142
- border: 2px solid #000 !important;
143
- }
144
-
145
- /* ★ダークモード時のボタン枠線を追加 */
146
- .dark .action-btn {
147
- border: 2px solid #fff !important;
148
- }
149
 
150
- #draw-btn { margin: 0px auto -5px auto !important; }
151
- #share-btn { margin: 0px auto 10px auto !important; }
 
152
  """
153
 
154
  with gr.Blocks(title="蓮ノ空聖書正典", css=custom_css, theme=gr.themes.Monochrome()) as demo:
155
- # 修正箇所: StateをTextboxに変更(非表示)
156
  device_id_storage = gr.Textbox(visible=False)
157
 
158
  demo.load(None, None, device_id_storage, js="""
@@ -168,28 +114,29 @@ with gr.Blocks(title="蓮ノ空聖書正典", css=custom_css, theme=gr.themes.Mo
168
 
169
  with gr.Column(elem_classes="center-content"):
170
  gr.Markdown("# ⚖️ 蓮ノ空聖書正典")
171
-
172
  gr.Markdown("日付が変わるまであなたの思想は<br>統一されます。", elem_id="doctrine")
173
 
174
  result_display = gr.HTML(elem_id="oracle-box", visible=False)
175
  peace_display = gr.Markdown(elem_id="peace-msg")
176
 
177
  draw_btn = gr.Button("神託を受ける", variant="primary", elem_id="draw-btn", elem_classes="action-btn")
178
- share_btn = gr.Button("信仰を広める", variant="secondary", elem_id="share-btn", elem_classes="action-btn", visible=False)
 
179
 
180
  draw_btn.click(
181
  fn=get_personal_daily_oracle,
182
  inputs=[device_id_storage],
183
- outputs=[result_display, peace_display, share_btn, result_display],
184
  js=js_logic
185
  ).then(
186
  fn=None,
187
- inputs=[result_display, peace_display, share_btn, result_display],
188
  outputs=None,
189
  js=js_save_result
190
  )
191
 
192
- share_btn.click(fn=None, inputs=None, outputs=None, js=js_share_bluesky)
 
193
 
194
  if __name__ == "__main__":
195
  demo.launch()
 
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")
 
23
  )
24
  peace_msg = "これにより、不毛なカップリング論争は終結しました。"
25
 
26
+ # 戻り値: oracle_html, peace_msg, bsky_btn_update, x_btn_update, result_box_update
27
+ return oracle_html, peace_msg, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
28
 
29
+ # JS: 状態チェックと復元
30
  js_logic = """
31
  function(deviceId) {
32
  const id = localStorage.getItem('cp_oracle_device_id') || "guest";
 
36
 
37
  if (lastDraw === today && lastPair) {
38
  alert("本日の神託は既に下されています。\\n明日の更新まで、今の思想を維持しなさい。");
39
+ return [id, lastPair, "これにより、不毛なカップリング論争は終結しました。", { "visible": true, "__type__": "update" }, { "visible": true, "__type__": "update" }, { "visible": true, "__type__": "update" }];
 
40
  }
41
 
42
  localStorage.setItem('lastOracleDate', today);
43
+ return [id, null, null, null, null, null];
 
44
  }
45
  """
46
 
47
  # JS: 結果の保存
48
  js_save_result = """
49
+ function(oracleHtml, peaceMsg, bskyBtn, xBtn, resultBox) {
50
  if (oracleHtml && oracleHtml.includes("本日の神託")) {
51
  localStorage.setItem('lastPairText', oracleHtml);
52
  }
53
  }
54
  """
55
 
56
+ # JS: 共通テキスト生成ロジッ
57
+ js_get_share_text = """
58
  function() {
59
  const pairRawEl = document.getElementById('pair-raw');
60
  let pairName = "";
 
61
  if (pairRawEl) {
62
  pairName = pairRawEl.innerText;
63
  } else {
 
65
  const match = lastPair.match(/>([^<]{4,})<\\/div>$/);
66
  pairName = match ? match[1] : "運命";
67
  }
 
68
  const currentUrl = window.location.href;
69
+ return `私は「${pairName}」信仰してます。\\n\\n蓮ノ空聖書正典:\\n${currentUrl}`;
 
 
 
70
  }
71
  """
72
 
73
+ # JS: 各SNSへの投稿
74
+ js_share_bluesky = f"function() {{ const text = ({js_get_share_text})(); window.open(`https://bsky.app/intent/compose?text=${{encodeURIComponent(text)}}`, '_blank'); }}"
75
+ js_share_x = f"function() {{ const text = ({js_get_share_text})(); window.open(`https://twitter.com/intent/tweet?text=${{encodeURIComponent(text)}}`, '_blank'); }}"
76
+
77
  custom_css = """
78
  .gradio-container { max-width: 600px !important; text-align: center !important; }
79
+ .center-content { display: flex !important; flex-direction: column !important; align-items: center !important; padding-top: 45px !important; }
80
+ h1 { margin-top: 0px !important; margin-bottom: -5px !important; font-size: 32px !important; }
81
+ #doctrine { font-size: 1.5em !important; line-height: 1.4 !important; font-weight: bold !important; margin-bottom: -5px !important; text-align: center !important; }
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  #oracle-box {
84
+ color: #000 !important; background: #fff !important; border: 4px solid #000 !important;
85
+ padding: 25px 10px !important; line-height: 1.1 !important; min-height: 130px !important;
86
+ display: flex !important; flex-direction: column !important; justify-content: center !important;
 
 
 
 
 
 
87
  margin: 0px auto -5px auto !important;
88
  }
89
+ .dark #oracle-box { color: #fff !important; background: #000 !important; border: 4px solid #fff !important; }
90
 
91
+ #peace-msg { font-size: 20px !important; font-weight: bold !important; color: #d63031 !important; margin: 0px auto -5px auto !important; }
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
+ .action-btn { font-size: 24px !important; font-weight: bold !important; width: 320px !important; border: 2px solid #000 !important; }
94
+ .dark .action-btn { border: 2px solid #fff !important; }
 
 
 
 
 
 
 
 
 
 
 
95
 
96
+ #draw-btn { margin: 0px auto -5px auto !important; height: 75px !important; font-size: 28px !important; }
97
+ #share-bsky { margin: 0px auto -5px auto !important; height: 60px !important; }
98
+ #share-x { margin: 0px auto 10px auto !important; height: 60px !important; }
99
  """
100
 
101
  with gr.Blocks(title="蓮ノ空聖書正典", css=custom_css, theme=gr.themes.Monochrome()) as demo:
 
102
  device_id_storage = gr.Textbox(visible=False)
103
 
104
  demo.load(None, None, device_id_storage, js="""
 
114
 
115
  with gr.Column(elem_classes="center-content"):
116
  gr.Markdown("# ⚖️ 蓮ノ空聖書正典")
 
117
  gr.Markdown("日付が変わるまであなたの思想は<br>統一されます。", elem_id="doctrine")
118
 
119
  result_display = gr.HTML(elem_id="oracle-box", visible=False)
120
  peace_display = gr.Markdown(elem_id="peace-msg")
121
 
122
  draw_btn = gr.Button("神託を受ける", variant="primary", elem_id="draw-btn", elem_classes="action-btn")
123
+ share_btn_x = gr.Button("Xで信仰を広める", variant="secondary", elem_id="share-x", elem_classes="action-btn", visible=False)
124
+ share_btn_bsky = gr.Button("Blueskyで信仰を広める", variant="secondary", elem_id="share-bsky", elem_classes="action-btn", visible=False)
125
 
126
  draw_btn.click(
127
  fn=get_personal_daily_oracle,
128
  inputs=[device_id_storage],
129
+ outputs=[result_display, peace_display, share_btn_bsky, share_btn_x, result_display],
130
  js=js_logic
131
  ).then(
132
  fn=None,
133
+ inputs=[result_display, peace_display, share_btn_bsky, share_btn_x, result_display],
134
  outputs=None,
135
  js=js_save_result
136
  )
137
 
138
+ share_btn_bsky.click(fn=None, inputs=None, outputs=None, js=js_share_bluesky)
139
+ share_btn_x.click(fn=None, inputs=None, outputs=None, js=js_share_x)
140
 
141
  if __name__ == "__main__":
142
  demo.launch()