Rathapoom commited on
Commit
7b346df
·
verified ·
1 Parent(s): 682335c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -65
app.py CHANGED
@@ -3181,83 +3181,35 @@ def generate_stitched_story(story: List[dict], style: str, detail_level: str, th
3181
  def show_stitched_result(story_data: Dict[str, str]):
3182
  """Display the stitched story result with enhanced formatting"""
3183
  try:
3184
- st.markdown("## 📖 Your Polished Story | เรื่องราวฉบับสมบูรณ์")
 
 
 
 
 
 
3185
 
3186
  # English Version
3187
- st.markdown("### 🇬🇧 English Version")
3188
  st.markdown(
3189
- f"""<div style="background-color: #f8f9fa; padding: 20px;
3190
- border-radius: 10px; margin: 10px 0; border-left: 4px solid #1565c0;">
3191
- {story_data['polished_english']}
3192
- </div>""",
3193
  unsafe_allow_html=True
3194
  )
3195
 
3196
  # Thai Version
3197
- st.markdown("### 🇹🇭 ฉบับภาษาไทย")
3198
  st.markdown(
3199
- f"""<div style="background-color: #f8f9fa; padding: 20px;
3200
- border-radius: 10px; margin: 10px 0; border-left: 4px solid #4caf50;">
3201
- {story_data['thai_translation']}
3202
- </div>""",
3203
  unsafe_allow_html=True
3204
  )
3205
-
3206
- # Save options
3207
- st.markdown("### 💾 บันทึกเรื่องราว")
3208
-
3209
- save_col1, save_col2 = st.columns(2)
3210
-
3211
- with save_col1:
3212
- if st.button("📥 บันทึกเป็น PDF",
3213
- key="save_final_pdf",
3214
- use_container_width=True):
3215
- try:
3216
- pdf_data = create_bilingual_story_pdf(story_data)
3217
- file_name = f"my_story_{datetime.now().strftime('%Y%m%d_%H%M')}.pdf"
3218
- st.download_button(
3219
- "ดาวน์โหลด PDF",
3220
- data=pdf_data,
3221
- file_name=file_name,
3222
- mime="application/pdf",
3223
- key="download_final_pdf"
3224
- )
3225
- st.success("สร้าง PDF เรียบร้อยแล้ว!")
3226
- except Exception as e:
3227
- logging.error(f"Error saving PDF: {str(e)}")
3228
- st.error("เกิดข้อผิดพลาดในการสร้างไฟล์ PDF")
3229
-
3230
- with save_col2:
3231
- if st.button("📝 บันทึกข้อความ",
3232
- key="save_final_text",
3233
- use_container_width=True):
3234
- try:
3235
- text_data = json.dumps(story_data, ensure_ascii=False, indent=2)
3236
- file_name = f"my_story_{datetime.now().strftime('%Y%m%d_%H%M')}.json"
3237
- st.download_button(
3238
- "ดาวน์โหลดข้อความ",
3239
- data=text_data,
3240
- file_name=file_name,
3241
- mime="application/json",
3242
- key="download_final_text"
3243
- )
3244
- st.success("บันทึกข้อความเรียบร้อยแล้ว!")
3245
- except Exception as e:
3246
- logging.error(f"Error saving text: {str(e)}")
3247
- st.error("เกิดข้อผิดพลาดในการบันทึกข้อความ")
3248
-
3249
- # New story option
3250
- if st.button("🔄 เริ่มเรื่องใหม่",
3251
- key="new_story_after_stitch",
3252
- use_container_width=True):
3253
- if st.checkbox("✅ ยืนยันการเริ่มใหม่",
3254
- key="confirm_new_after_stitch"):
3255
- reset_story()
3256
- st.rerun()
3257
-
3258
  except Exception as e:
3259
  logging.error(f"Error showing stitched result: {str(e)}")
3260
- st.error("เกิดข้อผิดพลาดในการแสดงผลลัพธ์")
3261
 
3262
  def show_save_dialog():
3263
  """Display save options dialog"""
 
3181
  def show_stitched_result(story_data: Dict[str, str]):
3182
  """Display the stitched story result with enhanced formatting"""
3183
  try:
3184
+ # Check if story data exists
3185
+ if not story_data or not isinstance(story_data, dict):
3186
+ st.error("ไม่พบข้อมูลเรื่องราว กรุณาลองใหม่อีกครั้ง")
3187
+ return
3188
+
3189
+ # Header
3190
+ st.markdown("### 📖 Your Polished Story | เรื่องราวฉบับสมบูรณ์")
3191
 
3192
  # English Version
3193
+ st.subheader("🇬🇧 English Version")
3194
  st.markdown(
3195
+ f'<div style="background-color: white; padding: 15px; border-radius: 8px; margin-bottom: 15px;">'
3196
+ f'{story_data.get("polished_english", "No content available")}'
3197
+ f'</div>',
 
3198
  unsafe_allow_html=True
3199
  )
3200
 
3201
  # Thai Version
3202
+ st.subheader("🇹🇭 ฉบับภาษาไทย")
3203
  st.markdown(
3204
+ f'<div style="background-color: white; padding: 15px; border-radius: 8px;">'
3205
+ f'{story_data.get("thai_translation", "ไม่พบเนื้อหา")}'
3206
+ f'</div>',
 
3207
  unsafe_allow_html=True
3208
  )
3209
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3210
  except Exception as e:
3211
  logging.error(f"Error showing stitched result: {str(e)}")
3212
+ st.error("เกิดข้อผิดพลาดในการแสดงผลเรื���องราว กรุณาลองใหม่อีกครั้ง")
3213
 
3214
  def show_save_dialog():
3215
  """Display save options dialog"""