Rathapoom commited on
Commit
902f55a
·
verified ·
1 Parent(s): 140f5be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -40
app.py CHANGED
@@ -3080,7 +3080,7 @@ def show_story_stitching_options():
3080
  st.error("เกิดข้อผิดพลาดในการแสดงตัวเลือกการเรียบเรียง")
3081
 
3082
  def generate_stitched_story(story: List[dict], style: str, detail_level: str, theme: str, level: str) -> Dict[str, str]:
3083
- """Generate a polished version of the story with balanced additional details"""
3084
  try:
3085
  # แยกประโยคต่างๆ ตาม role
3086
  story_parts = {
@@ -3090,83 +3090,80 @@ def generate_stitched_story(story: List[dict], style: str, detail_level: str, th
3090
  'ending': next((entry['content'] for entry in story if entry.get('is_final')), '')
3091
  }
3092
 
3093
- # สร้าง prompt ที่เน้นการเพิ่มรายละเอียดอย่างสมดุล
3094
  prompt_template = f"""
3095
- Rewrite this story into a flowing narrative.
3096
-
3097
- IMPORTANT RULES:
3098
- 1. Keep all original sentences and events intact
3099
- 2. Add appropriate setting details and context
3100
- 3. Include simple descriptive elements that enhance the story
3101
- 4. Add natural transitions between events
3102
- 5. Keep additional details balanced and relevant
3103
- 6. Maintain the exact sequence of events
3104
-
3105
- Enhancement Guidelines:
3106
- - Add setting details (where things happen)
3107
- - Include character reactions and emotions
3108
- - Add simple descriptive words for actions
3109
- - Create smooth transitions between scenes
3110
- - Keep the magical/whimsical tone of the story
3111
-
3112
- Original Story Structure:
3113
  - Beginning: {story_parts['starter']}
3114
  - Main Story: {' '.join(sum(zip(story_parts['user_sentences'], story_parts['ai_responses']), ()))}
3115
  - Ending: {story_parts['ending']}
3116
 
3117
- Style: {style}
3118
- Level: {level}
3119
-
3120
- Create an enhanced narrative that preserves all original events while adding appropriate context and descriptions.
3121
  """
3122
 
3123
- # Generate English version with balanced details
3124
  response = client.chat.completions.create(
3125
- model="gpt-4o-mini",
3126
  messages=[
3127
  {
3128
  "role": "system",
3129
- "content": """You are a story editor who enhances stories while preserving their original content.
3130
- Focus on adding just enough detail to make the story more engaging without overshadowing the original events."""
 
3131
  },
3132
  {
3133
  "role": "user",
3134
  "content": prompt_template
3135
  }
3136
  ],
3137
- temperature=0.7
3138
  )
3139
 
3140
  polished_english = response.choices[0].message.content.strip()
3141
 
3142
- # Generate Thai translation with similar enhancement approach
3143
  translation_prompt = f"""
3144
- Translate this enhanced story to Thai.
3145
-
3146
  IMPORTANT:
3147
- 1. Maintain the same level of detail as the English version
3148
- 2. Keep all story elements and added descriptions
3149
- 3. Translate naturally while preserving the story's tone
3150
- 4. Ensure the magical elements come through clearly
3151
 
3152
  Story to translate:
3153
  {polished_english}
3154
  """
3155
 
3156
  translation_response = client.chat.completions.create(
3157
- model="gpt-4o-mini",
3158
  messages=[
3159
  {
3160
  "role": "system",
3161
- "content": """You are a Thai translator who specializes in children's stories.
3162
- Maintain the enhanced details while creating a natural Thai narrative."""
3163
  },
3164
  {
3165
  "role": "user",
3166
  "content": translation_prompt
3167
  }
3168
  ],
3169
- temperature=0.7
3170
  )
3171
 
3172
  thai_translation = translation_response.choices[0].message.content.strip()
 
3080
  st.error("เกิดข้อผิดพลาดในการแสดงตัวเลือกการเรียบเรียง")
3081
 
3082
  def generate_stitched_story(story: List[dict], style: str, detail_level: str, theme: str, level: str) -> Dict[str, str]:
3083
+ """Generate a polished version of the story with minimal enhancements"""
3084
  try:
3085
  # แยกประโยคต่างๆ ตาม role
3086
  story_parts = {
 
3090
  'ending': next((entry['content'] for entry in story if entry.get('is_final')), '')
3091
  }
3092
 
3093
+ # สร้าง prompt ที่เน้นการรักษาประโยคเดิมและเชื่อมต่อแบบกระชับ
3094
  prompt_template = f"""
3095
+ Rewrite this story into a flowing narrative.
3096
+
3097
+ CRITICAL RULES:
3098
+ 1. Keep original sentences almost exactly as they are
3099
+ 2. Add only minimal connecting words or phrases
3100
+ 3. Do not add new scenes or events
3101
+ 4. Do not add lengthy descriptions
3102
+ 5. Focus on making the story flow naturally
3103
+ 6. Keep any additions very brief and simple
3104
+
3105
+ Examples of good enhancement:
3106
+ Original: "The project started. We made robots."
3107
+ Good: "The project started with great excitement. We made robots, our first real creation."
3108
+ BAD: "In the sunny classroom, with students gathered around shiny tables, the project started. We made incredible robots with flashing lights and complex circuits."
3109
+
3110
+ Original Story Parts:
 
 
3111
  - Beginning: {story_parts['starter']}
3112
  - Main Story: {' '.join(sum(zip(story_parts['user_sentences'], story_parts['ai_responses']), ()))}
3113
  - Ending: {story_parts['ending']}
3114
 
3115
+ Create a coherent story that stays very close to the original while making it flow smoothly.
3116
+ Remember: Less is more - add only what's necessary for flow.
 
 
3117
  """
3118
 
3119
+ # Generate English version with minimal enhancements
3120
  response = client.chat.completions.create(
3121
+ model="gpt-4",
3122
  messages=[
3123
  {
3124
  "role": "system",
3125
+ "content": """You are a story editor who specializes in minimal enhancement.
3126
+ Your goal is to make the story flow while keeping it as close as possible to the original.
3127
+ Remember: Only add what's absolutely necessary for coherence."""
3128
  },
3129
  {
3130
  "role": "user",
3131
  "content": prompt_template
3132
  }
3133
  ],
3134
+ temperature=0.5 # Lower temperature for more consistent, conservative output
3135
  )
3136
 
3137
  polished_english = response.choices[0].message.content.strip()
3138
 
3139
+ # Generate Thai translation with same minimal approach
3140
  translation_prompt = f"""
3141
+ Translate this story to Thai.
3142
+
3143
  IMPORTANT:
3144
+ 1. Keep the translation concise and close to the English version
3145
+ 2. Do not add extra details or explanations
3146
+ 3. Maintain the same level of simplicity
3147
+ 4. Focus on natural Thai flow while keeping original content
3148
 
3149
  Story to translate:
3150
  {polished_english}
3151
  """
3152
 
3153
  translation_response = client.chat.completions.create(
3154
+ model="gpt-4",
3155
  messages=[
3156
  {
3157
  "role": "system",
3158
+ "content": """You are a Thai translator who specializes in concise, accurate translations.
3159
+ Keep the same level of detail as the English version without adding extra elements."""
3160
  },
3161
  {
3162
  "role": "user",
3163
  "content": translation_prompt
3164
  }
3165
  ],
3166
+ temperature=0.5
3167
  )
3168
 
3169
  thai_translation = translation_response.choices[0].message.content.strip()