Update app.py
Browse files
app.py
CHANGED
@@ -2486,6 +2486,9 @@ def show_save_dialog():
|
|
2486 |
except Exception as e:
|
2487 |
logging.error(f"Error saving progress: {str(e)}")
|
2488 |
st.error("เกิดข้อผิดพลาดในการบันทึกความก้าวหน้า")
|
|
|
|
|
|
|
2489 |
|
2490 |
def reset_story_with_confirmation():
|
2491 |
"""Reset story with confirmation dialog"""
|
@@ -2501,6 +2504,55 @@ def reset_story_with_confirmation():
|
|
2501 |
logging.error(f"Error in reset confirmation: {str(e)}")
|
2502 |
st.error("เกิดข้อผิดพลาดในการรีเซ็ตเรื่อง")
|
2503 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2504 |
# === 6. MAIN APPLICATION LOGIC ===
|
2505 |
def main():
|
2506 |
try:
|
|
|
2486 |
except Exception as e:
|
2487 |
logging.error(f"Error saving progress: {str(e)}")
|
2488 |
st.error("เกิดข้อผิดพลาดในการบันทึกความก้าวหน้า")
|
2489 |
+
except Exception as e:
|
2490 |
+
logging.error(f"Error showing save dialog: {str(e)}")
|
2491 |
+
st.error("เกิดข้อผิดพลาดในการแสดงตัวเลือกการบันทึก")
|
2492 |
|
2493 |
def reset_story_with_confirmation():
|
2494 |
"""Reset story with confirmation dialog"""
|
|
|
2504 |
logging.error(f"Error in reset confirmation: {str(e)}")
|
2505 |
st.error("เกิดข้อผิดพลาดในการรีเซ็ตเรื่อง")
|
2506 |
|
2507 |
+
def create_story_pdf():
|
2508 |
+
"""Create PDF of the story"""
|
2509 |
+
try:
|
2510 |
+
buffer = io.BytesIO()
|
2511 |
+
doc = SimpleDocTemplate(buffer, pagesize=A4)
|
2512 |
+
story_elements = []
|
2513 |
+
|
2514 |
+
# Add title
|
2515 |
+
styles = getSampleStyleSheet()
|
2516 |
+
title_style = ParagraphStyle(
|
2517 |
+
'CustomTitle',
|
2518 |
+
parent=styles['Title'],
|
2519 |
+
fontSize=24,
|
2520 |
+
spaceAfter=30
|
2521 |
+
)
|
2522 |
+
story_elements.append(Paragraph("My Story", title_style))
|
2523 |
+
|
2524 |
+
# Add content
|
2525 |
+
content_style = ParagraphStyle(
|
2526 |
+
'CustomBody',
|
2527 |
+
parent=styles['Normal'],
|
2528 |
+
fontSize=12,
|
2529 |
+
leading=16,
|
2530 |
+
spaceAfter=12
|
2531 |
+
)
|
2532 |
+
|
2533 |
+
for entry in st.session_state.story:
|
2534 |
+
if entry['role'] == 'AI':
|
2535 |
+
color = colors.blue
|
2536 |
+
else:
|
2537 |
+
color = colors.black
|
2538 |
+
|
2539 |
+
p = Paragraph(
|
2540 |
+
f"<font color={color}>{entry['content']}</font>",
|
2541 |
+
content_style
|
2542 |
+
)
|
2543 |
+
story_elements.append(p)
|
2544 |
+
|
2545 |
+
# Build PDF
|
2546 |
+
doc.build(story_elements)
|
2547 |
+
pdf = buffer.getvalue()
|
2548 |
+
buffer.close()
|
2549 |
+
|
2550 |
+
return pdf
|
2551 |
+
|
2552 |
+
except Exception as e:
|
2553 |
+
logging.error(f"Error creating PDF: {str(e)}")
|
2554 |
+
raise
|
2555 |
+
|
2556 |
# === 6. MAIN APPLICATION LOGIC ===
|
2557 |
def main():
|
2558 |
try:
|