Update app.py
Browse files
app.py
CHANGED
@@ -846,6 +846,47 @@ def generate_dynamic_story_starter(theme_id: str, level: str) -> Dict[str, str]:
|
|
846 |
'th': 'กาลครั้งหนึ่ง...'
|
847 |
}
|
848 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
849 |
def update_points(is_correct_first_try: bool):
|
850 |
"""อัพเดตคะแนนตามผลการเขียน"""
|
851 |
try:
|
@@ -2027,16 +2068,7 @@ def show_main_interface():
|
|
2027 |
|
2028 |
# === 6. MAIN APPLICATION LOGIC ===
|
2029 |
def main():
|
2030 |
-
"""Main application entry point"""
|
2031 |
try:
|
2032 |
-
# Page config
|
2033 |
-
st.set_page_config(
|
2034 |
-
page_title="JoyStory - Interactive Story Adventure",
|
2035 |
-
page_icon="📖",
|
2036 |
-
layout="wide",
|
2037 |
-
initial_sidebar_state="collapsed"
|
2038 |
-
)
|
2039 |
-
|
2040 |
# Initialize states
|
2041 |
init_session_state()
|
2042 |
init_theme_state()
|
@@ -2049,72 +2081,18 @@ def main():
|
|
2049 |
</div>
|
2050 |
""", unsafe_allow_html=True)
|
2051 |
|
2052 |
-
# แสดงแถบเตือนด้านบนเมื่อเริ่มต้นใช้งาน
|
2053 |
-
if 'show_settings_notice' not in st.session_state:
|
2054 |
-
st.session_state.show_settings_notice = True
|
2055 |
-
|
2056 |
-
if st.session_state.show_settings_notice:
|
2057 |
-
st.info("""
|
2058 |
-
💡 **คำแนะนำ:** คลิกที่ ≡ มุมซ้ายบนเพื่อตั้งค่าระดับความยาก (Beginner, Intermediate, Advanced)
|
2059 |
-
และโหลดความก้าวหน้าของคุณ
|
2060 |
-
""")
|
2061 |
-
if st.button("✕ ซ่อนคำแนะนำ"):
|
2062 |
-
st.session_state.show_settings_notice = False
|
2063 |
-
st.rerun()
|
2064 |
-
|
2065 |
# Show header
|
2066 |
st.markdown("# 📖 JoyStory")
|
2067 |
show_welcome_section()
|
2068 |
show_parent_guide()
|
2069 |
|
2070 |
-
# Sidebar
|
2071 |
with st.sidebar:
|
2072 |
-
st.markdown("""
|
2073 |
-
<div style="text-align: center; padding: 10px; background-color: #f0f7ff;
|
2074 |
-
border-radius: 8px; margin-bottom: 20px;">
|
2075 |
-
<h3 style="color: #1e88e5; margin: 0;">⚙️ การตั้งค่า</h3>
|
2076 |
-
<p style="color: #666; margin: 10px 0 0 0; font-size: 0.9em;">
|
2077 |
-
ปรับแต่งระดับความยากและจัดการความก้าวหน้าของคุณ
|
2078 |
-
</p>
|
2079 |
-
</div>
|
2080 |
-
""", unsafe_allow_html=True)
|
2081 |
show_sidebar()
|
2082 |
|
2083 |
# Session Status Check
|
2084 |
check_session_status()
|
2085 |
|
2086 |
-
# แสดงตัวบ่งชี้ด้านข้าง (ถ้า sidebar ถูกซ่อนอยู่)
|
2087 |
-
if st.session_state.get('initial_load', True):
|
2088 |
-
st.markdown("""
|
2089 |
-
<div style="
|
2090 |
-
position: fixed;
|
2091 |
-
left: 10px;
|
2092 |
-
top: 50%;
|
2093 |
-
transform: translateY(-50%);
|
2094 |
-
background-color: #1e88e5;
|
2095 |
-
color: white;
|
2096 |
-
padding: 10px;
|
2097 |
-
border-radius: 0 8px 8px 0;
|
2098 |
-
box-shadow: 2px 2px 10px rgba(0,0,0,0.1);
|
2099 |
-
cursor: pointer;
|
2100 |
-
z-index: 1000;
|
2101 |
-
animation: pulse 2s infinite;
|
2102 |
-
">
|
2103 |
-
<div style="writing-mode: vertical-rl; text-orientation: mixed;">
|
2104 |
-
⚙️ ตั้งค่าระดับความ��าก
|
2105 |
-
</div>
|
2106 |
-
</div>
|
2107 |
-
|
2108 |
-
<style>
|
2109 |
-
@keyframes pulse {
|
2110 |
-
0% { transform: translateY(-50%) scale(1); }
|
2111 |
-
50% { transform: translateY(-50%) scale(1.05); }
|
2112 |
-
100% { transform: translateY(-50%) scale(1); }
|
2113 |
-
}
|
2114 |
-
</style>
|
2115 |
-
""", unsafe_allow_html=True)
|
2116 |
-
st.session_state.initial_load = False
|
2117 |
-
|
2118 |
# Main content area
|
2119 |
main_container = st.container()
|
2120 |
with main_container:
|
@@ -2131,49 +2109,12 @@ def main():
|
|
2131 |
if st.session_state.story:
|
2132 |
auto_save_progress()
|
2133 |
|
2134 |
-
# Add CSS for sidebar enhancement
|
2135 |
-
st.markdown("""
|
2136 |
-
<style>
|
2137 |
-
/* Highlight sidebar toggle button */
|
2138 |
-
[data-testid="baseButton-header"] {
|
2139 |
-
background-color: #e3f2fd !important;
|
2140 |
-
border-radius: 8px !important;
|
2141 |
-
animation: highlight 2s infinite;
|
2142 |
-
}
|
2143 |
-
|
2144 |
-
@keyframes highlight {
|
2145 |
-
0% { box-shadow: 0 0 0 0 rgba(30,136,229,0.4); }
|
2146 |
-
70% { box-shadow: 0 0 0 10px rgba(30,136,229,0); }
|
2147 |
-
100% { box-shadow: 0 0 0 0 rgba(30,136,229,0); }
|
2148 |
-
}
|
2149 |
-
|
2150 |
-
/* Style sidebar */
|
2151 |
-
.css-1d391kg {
|
2152 |
-
background-color: #fafafa;
|
2153 |
-
border-right: 1px solid #e0e0e0;
|
2154 |
-
}
|
2155 |
-
|
2156 |
-
/* Enhance sidebar buttons */
|
2157 |
-
.stButton > button {
|
2158 |
-
width: 100%;
|
2159 |
-
margin: 5px 0;
|
2160 |
-
border-radius: 8px;
|
2161 |
-
transition: all 0.2s;
|
2162 |
-
}
|
2163 |
-
|
2164 |
-
.stButton > button:hover {
|
2165 |
-
transform: translateY(-2px);
|
2166 |
-
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
2167 |
-
}
|
2168 |
-
</style>
|
2169 |
-
""", unsafe_allow_html=True)
|
2170 |
-
|
2171 |
except Exception as e:
|
2172 |
handle_application_error(e)
|
2173 |
|
2174 |
if __name__ == "__main__":
|
2175 |
main()
|
2176 |
-
|
2177 |
def check_session_status():
|
2178 |
"""Check and maintain session status"""
|
2179 |
try:
|
|
|
846 |
'th': 'กาลครั้งหนึ่ง...'
|
847 |
}
|
848 |
|
849 |
+
def handle_application_error(error: Exception):
|
850 |
+
"""Handle application-wide errors"""
|
851 |
+
logging.error(f"Application error: {str(error)}")
|
852 |
+
|
853 |
+
error_message = f"""
|
854 |
+
<div style="
|
855 |
+
background-color: #ffebee;
|
856 |
+
padding: 20px;
|
857 |
+
border-radius: 10px;
|
858 |
+
border-left: 4px solid #c62828;
|
859 |
+
margin: 20px 0;
|
860 |
+
">
|
861 |
+
<h3 style="color: #c62828; margin: 0 0 10px 0;">
|
862 |
+
⚠️ เกิดข้อผิดพลาดในระบบ
|
863 |
+
</h3>
|
864 |
+
<p style="color: #333; margin: 0;">
|
865 |
+
กรุณาลองใหม่อีกครั้ง หรือติดต่อผู้ดูแลระบบ
|
866 |
+
</p>
|
867 |
+
<div style="
|
868 |
+
margin-top: 10px;
|
869 |
+
padding: 10px;
|
870 |
+
background-color: #f5f5f5;
|
871 |
+
border-radius: 5px;
|
872 |
+
font-family: monospace;
|
873 |
+
font-size: 0.9em;
|
874 |
+
">
|
875 |
+
Error: {str(error)}
|
876 |
+
</div>
|
877 |
+
</div>
|
878 |
+
"""
|
879 |
+
|
880 |
+
st.markdown(error_message, unsafe_allow_html=True)
|
881 |
+
|
882 |
+
# Show technical details in expander
|
883 |
+
with st.expander("📋 รายละเอียดข้อผิดพลาด (สำหรับผู้ดูแลระบบ)"):
|
884 |
+
st.code(f"""
|
885 |
+
Error Type: {type(error).__name__}
|
886 |
+
Error Message: {str(error)}
|
887 |
+
Timestamp: {datetime.now().isoformat()}
|
888 |
+
""")
|
889 |
+
|
890 |
def update_points(is_correct_first_try: bool):
|
891 |
"""อัพเดตคะแนนตามผลการเขียน"""
|
892 |
try:
|
|
|
2068 |
|
2069 |
# === 6. MAIN APPLICATION LOGIC ===
|
2070 |
def main():
|
|
|
2071 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2072 |
# Initialize states
|
2073 |
init_session_state()
|
2074 |
init_theme_state()
|
|
|
2081 |
</div>
|
2082 |
""", unsafe_allow_html=True)
|
2083 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2084 |
# Show header
|
2085 |
st.markdown("# 📖 JoyStory")
|
2086 |
show_welcome_section()
|
2087 |
show_parent_guide()
|
2088 |
|
2089 |
+
# Sidebar
|
2090 |
with st.sidebar:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2091 |
show_sidebar()
|
2092 |
|
2093 |
# Session Status Check
|
2094 |
check_session_status()
|
2095 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2096 |
# Main content area
|
2097 |
main_container = st.container()
|
2098 |
with main_container:
|
|
|
2109 |
if st.session_state.story:
|
2110 |
auto_save_progress()
|
2111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2112 |
except Exception as e:
|
2113 |
handle_application_error(e)
|
2114 |
|
2115 |
if __name__ == "__main__":
|
2116 |
main()
|
2117 |
+
|
2118 |
def check_session_status():
|
2119 |
"""Check and maintain session status"""
|
2120 |
try:
|