Update app.py
Browse files
app.py
CHANGED
@@ -764,6 +764,43 @@ def generate_story_continuation(user_input: str, level: str) -> str:
|
|
764 |
logging.error(f"Error generating story continuation: {str(e)}")
|
765 |
return "I'm having trouble continuing the story. Please try again."
|
766 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
767 |
def provide_feedback(text: str, level: str) -> Dict[str, str]:
|
768 |
"""Provide feedback on the user's writing with appropriate level"""
|
769 |
|
|
|
764 |
logging.error(f"Error generating story continuation: {str(e)}")
|
765 |
return "I'm having trouble continuing the story. Please try again."
|
766 |
|
767 |
+
def generate_dynamic_story_starter(theme_id: str, level: str) -> Dict[str, str]:
|
768 |
+
"""
|
769 |
+
Dynamically generate a story starter based on theme and level.
|
770 |
+
Returns both Thai and English versions.
|
771 |
+
"""
|
772 |
+
try:
|
773 |
+
# Get theme data
|
774 |
+
theme = story_themes.get(theme_id)
|
775 |
+
if not theme:
|
776 |
+
raise ValueError(f"Theme {theme_id} not found")
|
777 |
+
|
778 |
+
# Get random starter for the level
|
779 |
+
level_starters = theme['story_starters'].get(level, [])
|
780 |
+
if not level_starters:
|
781 |
+
# Fallback to Beginner level if no starters found for specified level
|
782 |
+
level_starters = theme['story_starters'].get('Beginner', [])
|
783 |
+
|
784 |
+
if not level_starters:
|
785 |
+
raise ValueError(f"No story starters found for theme {theme_id}")
|
786 |
+
|
787 |
+
# Select random starter
|
788 |
+
starter = random.choice(level_starters)
|
789 |
+
|
790 |
+
# Return both languages
|
791 |
+
return {
|
792 |
+
'en': starter['en'],
|
793 |
+
'th': starter['th']
|
794 |
+
}
|
795 |
+
|
796 |
+
except Exception as e:
|
797 |
+
logging.error(f"Error generating story starter: {str(e)}")
|
798 |
+
# Provide fallback starter
|
799 |
+
return {
|
800 |
+
'en': 'Once upon a time...',
|
801 |
+
'th': 'กาลครั้งหนึ่ง...'
|
802 |
+
}
|
803 |
+
|
804 |
def provide_feedback(text: str, level: str) -> Dict[str, str]:
|
805 |
"""Provide feedback on the user's writing with appropriate level"""
|
806 |
|