Rathapoom commited on
Commit
21cdc12
·
verified ·
1 Parent(s): 35c5870

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -1599,10 +1599,10 @@ def show_story_progress():
1599
 
1600
  def show_story_ending_options():
1601
  """Display story ending options and guidance"""
1602
- if len(st.session_state.story) >= 10: # แสดงตัวเลือกเมื่อเรื่องยาวพอ
1603
  st.markdown("### 🎭 ต้องการจบเรื่องหรือไม่?")
1604
 
1605
- # แสดงตัวเลือกวิธีจบเรื่อง
1606
  ending_type = st.radio(
1607
  "เลือกวิธีจบเรื่อง:",
1608
  options=[
@@ -1619,7 +1619,7 @@ def show_story_ending_options():
1619
  st.session_state.ending_mode = True
1620
  st.session_state.ending_type = ending_type
1621
  st.session_state.sentences_to_end = 5
1622
- st.rerun()
1623
 
1624
  def handle_ending_mode(text: str):
1625
  """Handle story submission during ending mode"""
@@ -1634,12 +1634,12 @@ def handle_ending_mode(text: str):
1634
  "is_corrected": False,
1635
  "is_correct": True,
1636
  "timestamp": datetime.now().isoformat(),
1637
- "remaining_sentences": remaining # Include remaining sentences
1638
  })
1639
 
1640
  # Decrease remaining count for user's sentence
1641
  st.session_state.sentences_to_end -= 1
1642
- remaining = st.session_state.sentences_to_end # Update local variable
1643
 
1644
  if remaining > 0:
1645
  # Generate AI's ending continuation
@@ -1649,7 +1649,7 @@ def handle_ending_mode(text: str):
1649
  remaining_sentences=remaining
1650
  )
1651
 
1652
- # Add AI response with remaining count
1653
  st.session_state.story.append({
1654
  "role": "AI",
1655
  "content": ai_response,
@@ -1659,7 +1659,7 @@ def handle_ending_mode(text: str):
1659
 
1660
  # Decrease remaining sentences
1661
  st.session_state.sentences_to_end -= 1
1662
- remaining = st.session_state.sentences_to_end
1663
  else:
1664
  # Generate final ending
1665
  final_response = generate_final_ending(
@@ -1677,18 +1677,16 @@ def handle_ending_mode(text: str):
1677
 
1678
  # Mark story as complete
1679
  st.session_state.story_completed = True
1680
- complete_story()
1681
-
1682
  # Clear input and rerun
1683
  st.session_state.text_input = ""
1684
  st.session_state.clear_input = True
1685
- st.rerun()
1686
 
1687
  except Exception as e:
1688
  logging.error(f"Error in ending mode: {str(e)}")
1689
  st.error("เกิดข้อผิดพลาดในโหมดจบเรื่อง กรุณาลองใหม่อีกครั้ง")
1690
 
1691
-
1692
  def generate_final_ending(story: List[dict], ending_type: str) -> str:
1693
  """Generate the final ending sentence based on the story and chosen ending type"""
1694
  try:
@@ -2513,7 +2511,7 @@ def main():
2513
  st.session_state.sentences_to_end = 0
2514
  st.session_state.ending_type = None
2515
  st.session_state.story_completed = False
2516
- st.experimental_rerun()
2517
 
2518
  # Auto-save progress periodically
2519
  if st.session_state.story:
 
1599
 
1600
  def show_story_ending_options():
1601
  """Display story ending options and guidance"""
1602
+ if len(st.session_state.story) >= 10: # Show options when story is long enough
1603
  st.markdown("### 🎭 ต้องการจบเรื่องหรือไม่?")
1604
 
1605
+ # Display ending type options
1606
  ending_type = st.radio(
1607
  "เลือกวิธีจบเรื่อง:",
1608
  options=[
 
1619
  st.session_state.ending_mode = True
1620
  st.session_state.ending_type = ending_type
1621
  st.session_state.sentences_to_end = 5
1622
+ st.rerun() # Using st.rerun() instead of st.experimental_rerun()
1623
 
1624
  def handle_ending_mode(text: str):
1625
  """Handle story submission during ending mode"""
 
1634
  "is_corrected": False,
1635
  "is_correct": True,
1636
  "timestamp": datetime.now().isoformat(),
1637
+ "remaining_sentences": remaining
1638
  })
1639
 
1640
  # Decrease remaining count for user's sentence
1641
  st.session_state.sentences_to_end -= 1
1642
+ remaining = st.session_state.sentences_to_end
1643
 
1644
  if remaining > 0:
1645
  # Generate AI's ending continuation
 
1649
  remaining_sentences=remaining
1650
  )
1651
 
1652
+ # Add AI response
1653
  st.session_state.story.append({
1654
  "role": "AI",
1655
  "content": ai_response,
 
1659
 
1660
  # Decrease remaining sentences
1661
  st.session_state.sentences_to_end -= 1
1662
+
1663
  else:
1664
  # Generate final ending
1665
  final_response = generate_final_ending(
 
1677
 
1678
  # Mark story as complete
1679
  st.session_state.story_completed = True
1680
+
 
1681
  # Clear input and rerun
1682
  st.session_state.text_input = ""
1683
  st.session_state.clear_input = True
1684
+ st.rerun() # Using st.rerun() instead of st.experimental_rerun()
1685
 
1686
  except Exception as e:
1687
  logging.error(f"Error in ending mode: {str(e)}")
1688
  st.error("เกิดข้อผิดพลาดในโหมดจบเรื่อง กรุณาลองใหม่อีกครั้ง")
1689
 
 
1690
  def generate_final_ending(story: List[dict], ending_type: str) -> str:
1691
  """Generate the final ending sentence based on the story and chosen ending type"""
1692
  try:
 
2511
  st.session_state.sentences_to_end = 0
2512
  st.session_state.ending_type = None
2513
  st.session_state.story_completed = False
2514
+ st.rerun() # Using st.rerun() instead of st.experimental_rerun()
2515
 
2516
  # Auto-save progress periodically
2517
  if st.session_state.story: