Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,6 @@ from datetime import datetime, timedelta, timezone
|
|
| 6 |
members = ["かほ", "さや", "こず", "るり", "めぐ", "つづ", "ぎん", "すず", "ひめ", "せら", "いず", "さち"]
|
| 7 |
|
| 8 |
def get_personal_daily_oracle(device_id):
|
| 9 |
-
# device_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,7 +23,6 @@ def get_personal_daily_oracle(device_id):
|
|
| 24 |
)
|
| 25 |
peace_msg = "これにより、不毛なカップリング論争は終結しました。"
|
| 26 |
|
| 27 |
-
# [結果HTML, 終結文, 共有ボタン表示, 案内文表示]
|
| 28 |
return oracle_html, peace_msg, gr.update(visible=True), gr.update(visible=True)
|
| 29 |
|
| 30 |
# JS: 状態チェックと復元
|
|
@@ -36,7 +34,6 @@ function(deviceId) {
|
|
| 36 |
|
| 37 |
if (lastDraw === today && lastPair) {
|
| 38 |
alert("本日の神託は既に下されています。\\n明日の更新まで、今の思想を維持しなさい。");
|
| 39 |
-
// 戻り値を4つ(HTML, 終結文, 共有ボタン, 案内文)に対応
|
| 40 |
return [lastPair, "これにより、不毛なカップリング論争は終結しました。", { "visible": true, "__type__": "update" }, { "visible": true, "__type__": "update" }];
|
| 41 |
}
|
| 42 |
|
|
@@ -47,7 +44,7 @@ function(deviceId) {
|
|
| 47 |
|
| 48 |
# JS: 結果の保存
|
| 49 |
js_save_result = """
|
| 50 |
-
function(oracleHtml, peaceMsg, shareBtn,
|
| 51 |
if (oracleHtml && oracleHtml.includes("本日の神託")) {
|
| 52 |
localStorage.setItem('lastPairText', oracleHtml);
|
| 53 |
}
|
|
@@ -78,6 +75,7 @@ function() {
|
|
| 78 |
custom_css = """
|
| 79 |
.gradio-container { max-width: 600px !important; text-align: center !important; }
|
| 80 |
|
|
|
|
| 81 |
.center-content {
|
| 82 |
display: flex !important;
|
| 83 |
flex-direction: column !important;
|
|
@@ -85,12 +83,14 @@ custom_css = """
|
|
| 85 |
padding-top: 40px !important;
|
| 86 |
}
|
| 87 |
|
|
|
|
| 88 |
h1 {
|
| 89 |
margin-top: 0px !important;
|
| 90 |
margin-bottom: -5px !important;
|
| 91 |
font-size: 32px !important;
|
| 92 |
}
|
| 93 |
|
|
|
|
| 94 |
#doctrine {
|
| 95 |
font-size: 1.5em !important;
|
| 96 |
line-height: 1.4 !important;
|
|
@@ -99,6 +99,7 @@ h1 {
|
|
| 99 |
text-align: center !important;
|
| 100 |
}
|
| 101 |
|
|
|
|
| 102 |
#oracle-box {
|
| 103 |
color: #000 !important;
|
| 104 |
background: #fff !important;
|
|
@@ -112,6 +113,7 @@ h1 {
|
|
| 112 |
margin: 0px auto -5px auto !important;
|
| 113 |
}
|
| 114 |
|
|
|
|
| 115 |
#peace-msg {
|
| 116 |
font-size: 20px !important;
|
| 117 |
font-weight: bold !important;
|
|
@@ -119,6 +121,7 @@ h1 {
|
|
| 119 |
margin: 0px auto -5px auto !important;
|
| 120 |
}
|
| 121 |
|
|
|
|
| 122 |
.action-btn {
|
| 123 |
font-size: 26px !important;
|
| 124 |
font-weight: bold !important;
|
|
@@ -129,28 +132,17 @@ h1 {
|
|
| 129 |
|
| 130 |
#draw-btn { margin: 0px auto -5px auto !important; }
|
| 131 |
#share-btn { margin: 0px auto 10px auto !important; }
|
| 132 |
-
|
| 133 |
-
/* 案内文のスタイル:他のテキストと同様に黒く表示 */
|
| 134 |
-
#instruct-msg {
|
| 135 |
-
font-size: 18px !important;
|
| 136 |
-
font-weight: bold !important;
|
| 137 |
-
color: #000 !important;
|
| 138 |
-
margin: 0px auto 10px auto !important;
|
| 139 |
-
line-height: 1.5 !important;
|
| 140 |
-
background: transparent !important;
|
| 141 |
-
border: none !important;
|
| 142 |
-
}
|
| 143 |
"""
|
| 144 |
|
| 145 |
with gr.Blocks(title="蓮ノ空聖書正典", css=custom_css, theme=gr.themes.Monochrome()) as demo:
|
| 146 |
-
# 修正
|
| 147 |
device_id_storage = gr.Textbox(visible=False)
|
| 148 |
|
| 149 |
demo.load(None, None, device_id_storage, js="""
|
| 150 |
() => {
|
| 151 |
let id = localStorage.getItem('cp_oracle_device_id');
|
| 152 |
if(!id) {
|
| 153 |
-
id = Math.random().toString(36).substring(2, 15)
|
| 154 |
localStorage.setItem('cp_oracle_device_id', id);
|
| 155 |
}
|
| 156 |
return id;
|
|
@@ -166,24 +158,16 @@ with gr.Blocks(title="蓮ノ空聖書正典", css=custom_css, theme=gr.themes.Mo
|
|
| 166 |
peace_display = gr.Markdown(elem_id="peace-msg")
|
| 167 |
|
| 168 |
draw_btn = gr.Button("神託を受ける", variant="primary", elem_id="draw-btn", elem_classes="action-btn")
|
| 169 |
-
|
| 170 |
share_btn = gr.Button("信仰を広める", variant="secondary", elem_id="share-btn", elem_classes="action-btn", visible=False)
|
| 171 |
-
|
| 172 |
-
# 案内文の追加
|
| 173 |
-
instruct_msg = gr.HTML(
|
| 174 |
-
"画像を添えて<br>その導きを世界へ示しなさい。",
|
| 175 |
-
elem_id="instruct-msg",
|
| 176 |
-
visible=False
|
| 177 |
-
)
|
| 178 |
|
| 179 |
draw_btn.click(
|
| 180 |
fn=get_personal_daily_oracle,
|
| 181 |
inputs=[device_id_storage],
|
| 182 |
-
outputs=[result_display, peace_display, share_btn,
|
| 183 |
js=js_logic
|
| 184 |
).then(
|
| 185 |
fn=None,
|
| 186 |
-
inputs=[result_display, peace_display, share_btn,
|
| 187 |
outputs=None,
|
| 188 |
js=js_save_result
|
| 189 |
)
|
|
|
|
| 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 |
return oracle_html, peace_msg, gr.update(visible=True), gr.update(visible=True)
|
| 27 |
|
| 28 |
# JS: 状態チェックと復元
|
|
|
|
| 34 |
|
| 35 |
if (lastDraw === today && lastPair) {
|
| 36 |
alert("本日の神託は既に下されています。\\n明日の更新まで、今の思想を維持しなさい。");
|
|
|
|
| 37 |
return [lastPair, "これにより、不毛なカップリング論争は終結しました。", { "visible": true, "__type__": "update" }, { "visible": true, "__type__": "update" }];
|
| 38 |
}
|
| 39 |
|
|
|
|
| 44 |
|
| 45 |
# JS: 結果の保存
|
| 46 |
js_save_result = """
|
| 47 |
+
function(oracleHtml, peaceMsg, shareBtn, resultBox) {
|
| 48 |
if (oracleHtml && oracleHtml.includes("本日の神託")) {
|
| 49 |
localStorage.setItem('lastPairText', oracleHtml);
|
| 50 |
}
|
|
|
|
| 75 |
custom_css = """
|
| 76 |
.gradio-container { max-width: 600px !important; text-align: center !important; }
|
| 77 |
|
| 78 |
+
/* 1. 最上部の空白を40pxに設定 */
|
| 79 |
.center-content {
|
| 80 |
display: flex !important;
|
| 81 |
flex-direction: column !important;
|
|
|
|
| 83 |
padding-top: 40px !important;
|
| 84 |
}
|
| 85 |
|
| 86 |
+
/* 2. タイトルと教義の間を-5px */
|
| 87 |
h1 {
|
| 88 |
margin-top: 0px !important;
|
| 89 |
margin-bottom: -5px !important;
|
| 90 |
font-size: 32px !important;
|
| 91 |
}
|
| 92 |
|
| 93 |
+
/* 3. 教義と結果の間を-5px */
|
| 94 |
#doctrine {
|
| 95 |
font-size: 1.5em !important;
|
| 96 |
line-height: 1.4 !important;
|
|
|
|
| 99 |
text-align: center !important;
|
| 100 |
}
|
| 101 |
|
| 102 |
+
/* 4. 結果ボックスと終結文の間を-5px */
|
| 103 |
#oracle-box {
|
| 104 |
color: #000 !important;
|
| 105 |
background: #fff !important;
|
|
|
|
| 113 |
margin: 0px auto -5px auto !important;
|
| 114 |
}
|
| 115 |
|
| 116 |
+
/* 5. 終結文とボタンの間を-5px */
|
| 117 |
#peace-msg {
|
| 118 |
font-size: 20px !important;
|
| 119 |
font-weight: bold !important;
|
|
|
|
| 121 |
margin: 0px auto -5px auto !important;
|
| 122 |
}
|
| 123 |
|
| 124 |
+
/* 6. ボタン同士の間を-5px */
|
| 125 |
.action-btn {
|
| 126 |
font-size: 26px !important;
|
| 127 |
font-weight: bold !important;
|
|
|
|
| 132 |
|
| 133 |
#draw-btn { margin: 0px auto -5px auto !important; }
|
| 134 |
#share-btn { margin: 0px auto 10px auto !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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="""
|
| 142 |
() => {
|
| 143 |
let id = localStorage.getItem('cp_oracle_device_id');
|
| 144 |
if(!id) {
|
| 145 |
+
id = Math.random().toString(36).substring(2, 15);
|
| 146 |
localStorage.setItem('cp_oracle_device_id', id);
|
| 147 |
}
|
| 148 |
return id;
|
|
|
|
| 158 |
peace_display = gr.Markdown(elem_id="peace-msg")
|
| 159 |
|
| 160 |
draw_btn = gr.Button("神託を受ける", variant="primary", elem_id="draw-btn", elem_classes="action-btn")
|
|
|
|
| 161 |
share_btn = gr.Button("信仰を広める", variant="secondary", elem_id="share-btn", elem_classes="action-btn", visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
draw_btn.click(
|
| 164 |
fn=get_personal_daily_oracle,
|
| 165 |
inputs=[device_id_storage],
|
| 166 |
+
outputs=[result_display, peace_display, share_btn, result_display],
|
| 167 |
js=js_logic
|
| 168 |
).then(
|
| 169 |
fn=None,
|
| 170 |
+
inputs=[result_display, peace_display, share_btn, result_display],
|
| 171 |
outputs=None,
|
| 172 |
js=js_save_result
|
| 173 |
)
|