Update app.py
Browse files
app.py
CHANGED
@@ -2423,16 +2423,20 @@ def show_completion_options():
|
|
2423 |
help="อัตราการเขียนถูกต้อง"
|
2424 |
)
|
2425 |
|
2426 |
-
# Show action buttons
|
2427 |
st.markdown("### 🎯 ต้องการทำอะไรต่อ?")
|
2428 |
col1, col2 = st.columns(2)
|
2429 |
|
2430 |
with col1:
|
2431 |
-
if st.button("💾 บันทึกเรื่องราว",
|
|
|
|
|
2432 |
show_save_dialog()
|
2433 |
|
2434 |
with col2:
|
2435 |
-
if st.button("🔄 เริ่มเรื่องใหม่",
|
|
|
|
|
2436 |
reset_story_with_confirmation()
|
2437 |
|
2438 |
except Exception as e:
|
@@ -2447,23 +2451,28 @@ def show_save_dialog():
|
|
2447 |
col1, col2 = st.columns(2)
|
2448 |
|
2449 |
with col1:
|
2450 |
-
# PDF Export
|
2451 |
-
if st.button("📑 บันทึกเป็น PDF",
|
|
|
|
|
2452 |
try:
|
2453 |
pdf = create_story_pdf()
|
2454 |
st.download_button(
|
2455 |
"📥 ดาวน์โหลด PDF",
|
2456 |
data=pdf,
|
2457 |
file_name=f"story_{datetime.now().strftime('%Y%m%d')}.pdf",
|
2458 |
-
mime="application/pdf"
|
|
|
2459 |
)
|
2460 |
except Exception as e:
|
2461 |
logging.error(f"Error creating PDF: {str(e)}")
|
2462 |
st.error("เกิดข้อผิดพลาดในการสร้างไฟล์ PDF")
|
2463 |
|
2464 |
with col2:
|
2465 |
-
# JSON Save
|
2466 |
-
if st.button("💾 บันทึกความก้าวหน้า",
|
|
|
|
|
2467 |
try:
|
2468 |
story_data = {
|
2469 |
'timestamp': datetime.now().isoformat(),
|
@@ -2481,7 +2490,8 @@ def show_save_dialog():
|
|
2481 |
"📥 ดาวน์โหลดไฟล์บันทึก",
|
2482 |
data=json.dumps(story_data, ensure_ascii=False, indent=2),
|
2483 |
file_name=f"story_progress_{datetime.now().strftime('%Y%m%d')}.json",
|
2484 |
-
mime="application/json"
|
|
|
2485 |
)
|
2486 |
except Exception as e:
|
2487 |
logging.error(f"Error saving progress: {str(e)}")
|
@@ -2494,9 +2504,12 @@ def reset_story_with_confirmation():
|
|
2494 |
"""Reset story with confirmation dialog"""
|
2495 |
try:
|
2496 |
if st.session_state.story:
|
2497 |
-
if st.checkbox("✅ ยืนยันการเริ่มใหม่"
|
|
|
2498 |
st.warning("การเริ่มใหม่จะลบเรื่องราวปัจจุบันทั้งหมด")
|
2499 |
-
if st.button("🔄 ยืนยันการเริ่มใหม่",
|
|
|
|
|
2500 |
reset_story()
|
2501 |
st.success("เริ่มต้นใหม่เรียบร้อยแล้ว!")
|
2502 |
st.rerun()
|
|
|
2423 |
help="อัตราการเขียนถูกต้อง"
|
2424 |
)
|
2425 |
|
2426 |
+
# Show action buttons with unique keys
|
2427 |
st.markdown("### 🎯 ต้องการทำอะไรต่อ?")
|
2428 |
col1, col2 = st.columns(2)
|
2429 |
|
2430 |
with col1:
|
2431 |
+
if st.button("💾 บันทึกเรื่องราว",
|
2432 |
+
key="save_story_completion",
|
2433 |
+
use_container_width=True):
|
2434 |
show_save_dialog()
|
2435 |
|
2436 |
with col2:
|
2437 |
+
if st.button("🔄 เริ่มเรื่องใหม่",
|
2438 |
+
key="new_story_completion",
|
2439 |
+
use_container_width=True):
|
2440 |
reset_story_with_confirmation()
|
2441 |
|
2442 |
except Exception as e:
|
|
|
2451 |
col1, col2 = st.columns(2)
|
2452 |
|
2453 |
with col1:
|
2454 |
+
# PDF Export with unique key
|
2455 |
+
if st.button("📑 บันทึกเป็น PDF",
|
2456 |
+
key="save_pdf_button",
|
2457 |
+
use_container_width=True):
|
2458 |
try:
|
2459 |
pdf = create_story_pdf()
|
2460 |
st.download_button(
|
2461 |
"📥 ดาวน์โหลด PDF",
|
2462 |
data=pdf,
|
2463 |
file_name=f"story_{datetime.now().strftime('%Y%m%d')}.pdf",
|
2464 |
+
mime="application/pdf",
|
2465 |
+
key="download_pdf_button"
|
2466 |
)
|
2467 |
except Exception as e:
|
2468 |
logging.error(f"Error creating PDF: {str(e)}")
|
2469 |
st.error("เกิดข้อผิดพลาดในการสร้างไฟล์ PDF")
|
2470 |
|
2471 |
with col2:
|
2472 |
+
# JSON Save with unique key
|
2473 |
+
if st.button("💾 บันทึกความก้าวหน้า",
|
2474 |
+
key="save_progress_button",
|
2475 |
+
use_container_width=True):
|
2476 |
try:
|
2477 |
story_data = {
|
2478 |
'timestamp': datetime.now().isoformat(),
|
|
|
2490 |
"📥 ดาวน์โหลดไฟล์บันทึก",
|
2491 |
data=json.dumps(story_data, ensure_ascii=False, indent=2),
|
2492 |
file_name=f"story_progress_{datetime.now().strftime('%Y%m%d')}.json",
|
2493 |
+
mime="application/json",
|
2494 |
+
key="download_json_button"
|
2495 |
)
|
2496 |
except Exception as e:
|
2497 |
logging.error(f"Error saving progress: {str(e)}")
|
|
|
2504 |
"""Reset story with confirmation dialog"""
|
2505 |
try:
|
2506 |
if st.session_state.story:
|
2507 |
+
if st.checkbox("✅ ยืนยันการเริ่มใหม่",
|
2508 |
+
key="reset_confirmation_checkbox"):
|
2509 |
st.warning("การเริ่มใหม่จะลบเรื่องราวปัจจุบันทั้งหมด")
|
2510 |
+
if st.button("🔄 ยืนยันการเริ่มใหม่",
|
2511 |
+
key="confirm_reset_button",
|
2512 |
+
use_container_width=True):
|
2513 |
reset_story()
|
2514 |
st.success("เริ่มต้นใหม่เรียบร้อยแล้ว!")
|
2515 |
st.rerun()
|