Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -659,7 +659,45 @@ def finish_or_retire(pages_json, current_page, pid, orig_lev, action, session_st
|
|
| 659 |
# ======================================================
|
| 660 |
# UI(タイトル表示を追加。それ以外は変更しない)
|
| 661 |
# ★追加:パスワード付きログCSVダウンロード
|
|
|
|
| 662 |
# ======================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 663 |
custom_css = """
|
| 664 |
/* ===============================
|
| 665 |
共通(両モード)
|
|
@@ -789,68 +827,33 @@ custom_css = """
|
|
| 789 |
}
|
| 790 |
|
| 791 |
/* ===============================
|
| 792 |
-
★Radioの「選択中」を確実に
|
| 793 |
=============================== */
|
| 794 |
-
|
| 795 |
-
/* まず選択肢の並びを「行っぽく」整える */
|
| 796 |
-
.gradio-container .gr-radio label {
|
| 797 |
display: flex !important;
|
| 798 |
align-items: center !important;
|
| 799 |
gap: 10px !important;
|
| 800 |
margin: 6px 0 !important;
|
|
|
|
|
|
|
| 801 |
}
|
| 802 |
|
| 803 |
-
/* labelの中にある “文字部分” が span のケースが多いので、spanを箱にする */
|
| 804 |
-
.gradio-container .gr-radio label > span {
|
| 805 |
-
display: block !important;
|
| 806 |
-
padding: 10px 12px !important;
|
| 807 |
-
border-radius: 10px !important;
|
| 808 |
-
border: 1px solid transparent !important;
|
| 809 |
-
}
|
| 810 |
-
|
| 811 |
-
/* checked のとき、inputの直後のspanをハイライト */
|
| 812 |
@media (prefers-color-scheme: light) {
|
| 813 |
-
|
| 814 |
background: #eef2ff !important;
|
| 815 |
-
border
|
| 816 |
-
color: #111 !important;
|
| 817 |
}
|
| 818 |
}
|
| 819 |
|
| 820 |
@media (prefers-color-scheme: dark) {
|
| 821 |
-
|
| 822 |
background: #1f2937 !important;
|
| 823 |
-
border
|
| 824 |
-
color: #f0f0f0 !important;
|
| 825 |
-
}
|
| 826 |
-
}
|
| 827 |
-
|
| 828 |
-
/* もし span じゃなく div になってる版のGradioでも効くように追加(保険) */
|
| 829 |
-
@media (prefers-color-scheme: light) {
|
| 830 |
-
.gradio-container .gr-radio label > input[type="radio"]:checked + div,
|
| 831 |
-
.gradio-container .gr-radio label > input[type="radio"]:checked + p {
|
| 832 |
-
background: #eef2ff !important;
|
| 833 |
-
border: 1px solid #c7d2fe !important;
|
| 834 |
-
border-radius: 10px !important;
|
| 835 |
-
padding: 10px 12px !important;
|
| 836 |
-
color: #111 !important;
|
| 837 |
-
}
|
| 838 |
-
}
|
| 839 |
-
|
| 840 |
-
@media (prefers-color-scheme: dark) {
|
| 841 |
-
.gradio-container .gr-radio label > input[type="radio"]:checked + div,
|
| 842 |
-
.gradio-container .gr-radio label > input[type="radio"]:checked + p {
|
| 843 |
-
background: #1f2937 !important;
|
| 844 |
-
border: 1px solid #374151 !important;
|
| 845 |
-
border-radius: 10px !important;
|
| 846 |
-
padding: 10px 12px !important;
|
| 847 |
-
color: #f0f0f0 !important;
|
| 848 |
}
|
| 849 |
}
|
| 850 |
"""
|
| 851 |
|
| 852 |
-
|
| 853 |
-
with gr.Blocks(css=custom_css) as demo:
|
| 854 |
gr.Markdown("# 📚 Reading Exercise")
|
| 855 |
|
| 856 |
session_state = gr.State({"user_id": None, "level": None, "group": 2, "used_passages": []})
|
|
@@ -860,7 +863,8 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 860 |
group_input = gr.Radio(
|
| 861 |
choices=[("Group 1", 1), ("Group 2", 2)],
|
| 862 |
label="実験グループを選択",
|
| 863 |
-
value=2
|
|
|
|
| 864 |
)
|
| 865 |
|
| 866 |
level_input = gr.Dropdown(
|
|
@@ -985,3 +989,4 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 985 |
|
| 986 |
demo.queue(max_size=64)
|
| 987 |
demo.launch()
|
|
|
|
|
|
| 659 |
# ======================================================
|
| 660 |
# UI(タイトル表示を追加。それ以外は変更しない)
|
| 661 |
# ★追加:パスワード付きログCSVダウンロード
|
| 662 |
+
# ★追加:Group Radioの選択中ハイライトをJSで確実化
|
| 663 |
# ======================================================
|
| 664 |
+
|
| 665 |
+
# ★追加:Group Radio専用ハイライトJS(DOM差を吸収して確実に効かせる)
|
| 666 |
+
radio_js = """
|
| 667 |
+
() => {
|
| 668 |
+
const root = document.getElementById("group_radio");
|
| 669 |
+
if (!root) return;
|
| 670 |
+
|
| 671 |
+
const update = () => {
|
| 672 |
+
// labelを全て取得してクラスを外す(Gradioの構造差を吸収)
|
| 673 |
+
const labels = root.querySelectorAll("label");
|
| 674 |
+
labels.forEach(l => l.classList.remove("radio-selected"));
|
| 675 |
+
|
| 676 |
+
// checkedなinputを探して、その親labelをハイライト
|
| 677 |
+
const checked = root.querySelector('input[type="radio"]:checked');
|
| 678 |
+
if (checked) {
|
| 679 |
+
const label = checked.closest("label");
|
| 680 |
+
if (label) label.classList.add("radio-selected");
|
| 681 |
+
}
|
| 682 |
+
};
|
| 683 |
+
|
| 684 |
+
// 初期反映
|
| 685 |
+
update();
|
| 686 |
+
|
| 687 |
+
// 変更時反映
|
| 688 |
+
root.addEventListener("change", update);
|
| 689 |
+
root.addEventListener("click", update);
|
| 690 |
+
|
| 691 |
+
// Gradioが描画を差し替える場合に備えて軽い再同期(短時間だけ)
|
| 692 |
+
let n = 0;
|
| 693 |
+
const t = setInterval(() => {
|
| 694 |
+
update();
|
| 695 |
+
n += 1;
|
| 696 |
+
if (n >= 10) clearInterval(t); // 約2秒で停止
|
| 697 |
+
}, 200);
|
| 698 |
+
};
|
| 699 |
+
"""
|
| 700 |
+
|
| 701 |
custom_css = """
|
| 702 |
/* ===============================
|
| 703 |
共通(両モード)
|
|
|
|
| 827 |
}
|
| 828 |
|
| 829 |
/* ===============================
|
| 830 |
+
★追加:Group Radio の「選択中」を確実にハイライト(JSが付与するクラス)
|
| 831 |
=============================== */
|
| 832 |
+
#group_radio label {
|
|
|
|
|
|
|
| 833 |
display: flex !important;
|
| 834 |
align-items: center !important;
|
| 835 |
gap: 10px !important;
|
| 836 |
margin: 6px 0 !important;
|
| 837 |
+
padding: 8px 10px !important;
|
| 838 |
+
border-radius: 12px !important;
|
| 839 |
}
|
| 840 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 841 |
@media (prefers-color-scheme: light) {
|
| 842 |
+
#group_radio label.radio-selected {
|
| 843 |
background: #eef2ff !important;
|
| 844 |
+
border: 2px solid #4f46e5 !important;
|
|
|
|
| 845 |
}
|
| 846 |
}
|
| 847 |
|
| 848 |
@media (prefers-color-scheme: dark) {
|
| 849 |
+
#group_radio label.radio-selected {
|
| 850 |
background: #1f2937 !important;
|
| 851 |
+
border: 2px solid #60a5fa !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 852 |
}
|
| 853 |
}
|
| 854 |
"""
|
| 855 |
|
| 856 |
+
with gr.Blocks(css=custom_css, js=radio_js) as demo:
|
|
|
|
| 857 |
gr.Markdown("# 📚 Reading Exercise")
|
| 858 |
|
| 859 |
session_state = gr.State({"user_id": None, "level": None, "group": 2, "used_passages": []})
|
|
|
|
| 863 |
group_input = gr.Radio(
|
| 864 |
choices=[("Group 1", 1), ("Group 2", 2)],
|
| 865 |
label="実験グループを選択",
|
| 866 |
+
value=2,
|
| 867 |
+
elem_id="group_radio" # ★追加:CSS/JSで確実に狙うため
|
| 868 |
)
|
| 869 |
|
| 870 |
level_input = gr.Dropdown(
|
|
|
|
| 989 |
|
| 990 |
demo.queue(max_size=64)
|
| 991 |
demo.launch()
|
| 992 |
+
|