Nyanpre commited on
Commit
52f9e2b
·
verified ·
1 Parent(s): e0fc92d

Create apppp.txt

Browse files
Files changed (1) hide show
  1. apppp.txt +195 -0
apppp.txt ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import random
3
+ from datetime import datetime, timedelta, timezone
4
+
5
+ # 12名の聖職者リスト
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")
13
+
14
+ random.seed(f"{seed_base}_{today_str}")
15
+
16
+ selected = random.sample(members, 2)
17
+ random.shuffle(selected)
18
+ pair_name = f"{selected[0]}{selected[1]}"
19
+
20
+ oracle_html = (
21
+ f"<div id='pair-raw' style='display:none;'>{pair_name}</div>"
22
+ f"<div style='font-size: 38px; font-weight: normal; margin-bottom: 2px;'>本日の神託</div>"
23
+ f"<div style='font-size: 52px; font-weight: 900; letter-spacing: 2px;'>{pair_name}</div>"
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";
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
+
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 {
67
+ const lastPair = localStorage.getItem('lastPairText') || "";
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="""
159
+ () => {
160
+ let id = localStorage.getItem('cp_oracle_device_id');
161
+ if(!id) {
162
+ id = Math.random().toString(36).substring(2, 15);
163
+ localStorage.setItem('cp_oracle_device_id', id);
164
+ }
165
+ return id;
166
+ }
167
+ """)
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()