Rathapoom commited on
Commit
bd91ee2
Β·
verified Β·
1 Parent(s): cc3c1dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -13
app.py CHANGED
@@ -62,7 +62,7 @@ def get_vocabulary_suggestions() -> List[str]:
62
  recent_story = '\n'.join([entry['content'] for entry in st.session_state.story[-3:]] if st.session_state.story else "Story just started")
63
 
64
  response = client.chat.completions.create(
65
- model="gpt-3.5-turbo",
66
  messages=[
67
  {"role": "system", "content": f"""You are a creative writing tutor for {st.session_state.level} English learners.
68
  Based on the story context, suggest 5 varied words that could be used next:
@@ -116,26 +116,55 @@ def get_creative_prompt() -> str:
116
  st.error(f"Error generating creative prompt: {str(e)}")
117
  return "What happens next in your story?"
118
 
119
- def provide_feedback(text: str, level: str) -> str:
120
- """Provide concise, constructive feedback on the user's writing."""
121
  try:
122
  response = client.chat.completions.create(
123
- model="gpt-3.5-turbo",
124
  messages=[
125
- {"role": "system", "content": f"""You are an encouraging English teacher for {level} students.
126
- Provide very brief feedback (max 15 words) focusing on ONE specific aspect:
127
- - Either praise a good point OR
128
- - Suggest one small improvement
129
- Keep it short and friendly."""},
130
- {"role": "user", "content": f"Give brief feedback on: {text}"}
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  ],
132
- max_tokens=30,
133
- temperature=0.6
134
  )
135
  return response.choices[0].message.content
136
  except Exception as e:
137
  st.error(f"Error generating feedback: {str(e)}")
138
- return "Good effort! Keep writing!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
  def update_achievements(text: str):
141
  """Update user achievements based on their writing."""
 
62
  recent_story = '\n'.join([entry['content'] for entry in st.session_state.story[-3:]] if st.session_state.story else "Story just started")
63
 
64
  response = client.chat.completions.create(
65
+ model="gpt-4o-mini",
66
  messages=[
67
  {"role": "system", "content": f"""You are a creative writing tutor for {st.session_state.level} English learners.
68
  Based on the story context, suggest 5 varied words that could be used next:
 
116
  st.error(f"Error generating creative prompt: {str(e)}")
117
  return "What happens next in your story?"
118
 
119
+ def provide_feedback(text: str, level: str) -> Dict[str, str]:
120
+ """Provide educational feedback with grammar explanation and encouragement."""
121
  try:
122
  response = client.chat.completions.create(
123
+ model="gpt-4o-mini",
124
  messages=[
125
+ {"role": "system", "content": f"""You are a friendly English teacher for {level} students of all ages.
126
+ Provide feedback in this format:
127
+ 1. One specific grammar or vocabulary point to learn
128
+ 2. The correct way to use it
129
+ 3. A simple, encouraging emoji
130
+
131
+ Keep each point very short and child-friendly.
132
+ Use simple explanations that a young learner can understand.
133
+ Always stay positive and encouraging.
134
+
135
+ Example:
136
+ "🌟 We use 'are' with plural nouns.
137
+ Instead of 'there is dogs', say 'there are dogs'!"
138
+
139
+ Or:
140
+ "🎯 Remember: Past tense of 'run' is 'ran'.
141
+ 'The dog ran to the park' ✨"
142
+ """},
143
+ {"role": "user", "content": f"Review this sentence and provide learning feedback: {text}"}
144
  ],
145
+ max_tokens=100,
146
+ temperature=0.7
147
  )
148
  return response.choices[0].message.content
149
  except Exception as e:
150
  st.error(f"Error generating feedback: {str(e)}")
151
+ return "🌟 Good try! Keep practicing!"
152
+
153
+ # In the main UI section, update how feedback is displayed:
154
+ if st.session_state.feedback:
155
+ st.markdown("### Learning Tips")
156
+ feedback_container = st.container()
157
+ with feedback_container:
158
+ st.markdown(f"""
159
+ <div style='background-color: #f0f2f6;
160
+ padding: 10px;
161
+ border-radius: 8px;
162
+ border-left: 4px solid #4CAF50;
163
+ margin: 5px 0;'>
164
+ {st.session_state.feedback}
165
+ </div>
166
+ """, unsafe_allow_html=True)
167
+
168
 
169
  def update_achievements(text: str):
170
  """Update user achievements based on their writing."""