Update app.py
Browse files
app.py
CHANGED
@@ -148,15 +148,21 @@ def get_vocabulary_suggestions() -> List[str]:
|
|
148 |
|
149 |
# Update the creative prompt function
|
150 |
def get_creative_prompt() -> Dict[str, str]:
|
151 |
-
"""Generate a bilingual creative prompt."""
|
152 |
try:
|
153 |
response = client.chat.completions.create(
|
154 |
model="gpt-4o-mini",
|
155 |
messages=[
|
156 |
-
{"role": "system", "content": "Create
|
157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
],
|
159 |
-
max_tokens=
|
160 |
temperature=0.7
|
161 |
)
|
162 |
prompt_eng = response.choices[0].message.content
|
@@ -165,10 +171,10 @@ def get_creative_prompt() -> Dict[str, str]:
|
|
165 |
response_thai = client.chat.completions.create(
|
166 |
model="gpt-4o-mini",
|
167 |
messages=[
|
168 |
-
{"role": "system", "content": "Translate
|
169 |
{"role": "user", "content": prompt_eng}
|
170 |
],
|
171 |
-
max_tokens=
|
172 |
temperature=0.7
|
173 |
)
|
174 |
prompt_thai = response_thai.choices[0].message.content
|
@@ -177,47 +183,51 @@ def get_creative_prompt() -> Dict[str, str]:
|
|
177 |
except Exception as e:
|
178 |
st.error(f"Error generating creative prompt: {str(e)}")
|
179 |
return {
|
180 |
-
"eng": "What happens next
|
181 |
-
"thai": "
|
182 |
}
|
183 |
|
184 |
-
def provide_feedback(text: str, level: str) ->
|
185 |
-
"""Provide educational feedback
|
186 |
try:
|
187 |
response = client.chat.completions.create(
|
188 |
model="gpt-4o-mini",
|
189 |
messages=[
|
190 |
-
{"role": "system", "content": f"""You are a
|
191 |
-
Provide feedback in
|
192 |
-
1.
|
193 |
-
2.
|
194 |
-
3.
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
Example:
|
201 |
-
"🌟 We use 'are' with plural nouns.
|
202 |
-
Instead of 'there is dogs', say 'there are dogs'!"
|
203 |
|
204 |
-
|
205 |
-
|
206 |
-
|
|
|
|
|
207 |
"""},
|
208 |
-
{"role": "user", "content": f"Review this sentence and provide
|
209 |
],
|
210 |
-
max_tokens=
|
211 |
temperature=0.7
|
212 |
)
|
213 |
return response.choices[0].message.content
|
214 |
except Exception as e:
|
215 |
st.error(f"Error generating feedback: {str(e)}")
|
216 |
-
return "🌟
|
217 |
|
218 |
-
#
|
219 |
if st.session_state.feedback:
|
220 |
-
st.markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
feedback_container = st.container()
|
222 |
with feedback_container:
|
223 |
st.markdown(f"""
|
@@ -225,11 +235,28 @@ def provide_feedback(text: str, level: str) -> Dict[str, str]:
|
|
225 |
padding: 10px;
|
226 |
border-radius: 8px;
|
227 |
border-left: 4px solid #4CAF50;
|
228 |
-
margin: 5px 0;
|
|
|
229 |
{st.session_state.feedback}
|
230 |
</div>
|
231 |
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
|
|
|
|
|
|
|
|
|
|
|
233 |
|
234 |
def update_achievements(text: str):
|
235 |
"""Update user achievements based on their writing."""
|
|
|
148 |
|
149 |
# Update the creative prompt function
|
150 |
def get_creative_prompt() -> Dict[str, str]:
|
151 |
+
"""Generate a short, simple bilingual creative prompt."""
|
152 |
try:
|
153 |
response = client.chat.completions.create(
|
154 |
model="gpt-4o-mini",
|
155 |
messages=[
|
156 |
+
{"role": "system", "content": """Create very short story prompts in both English and Thai.
|
157 |
+
Keep it simple and under 6 words each.
|
158 |
+
Example formats:
|
159 |
+
- "What did the cat find?"
|
160 |
+
- "Where did they go next?"
|
161 |
+
- "How does the story end?"
|
162 |
+
"""},
|
163 |
+
{"role": "user", "content": "Generate a simple, short story prompt:"}
|
164 |
],
|
165 |
+
max_tokens=50,
|
166 |
temperature=0.7
|
167 |
)
|
168 |
prompt_eng = response.choices[0].message.content
|
|
|
171 |
response_thai = client.chat.completions.create(
|
172 |
model="gpt-4o-mini",
|
173 |
messages=[
|
174 |
+
{"role": "system", "content": "Translate to short Thai prompt, keep it simple and natural:"},
|
175 |
{"role": "user", "content": prompt_eng}
|
176 |
],
|
177 |
+
max_tokens=50,
|
178 |
temperature=0.7
|
179 |
)
|
180 |
prompt_thai = response_thai.choices[0].message.content
|
|
|
183 |
except Exception as e:
|
184 |
st.error(f"Error generating creative prompt: {str(e)}")
|
185 |
return {
|
186 |
+
"eng": "What happens next?",
|
187 |
+
"thai": "แล้วอะไรจะเกิดขึ้นต่อ?"
|
188 |
}
|
189 |
|
190 |
+
def provide_feedback(text: str, level: str) -> str:
|
191 |
+
"""Provide educational feedback in Thai with English examples."""
|
192 |
try:
|
193 |
response = client.chat.completions.create(
|
194 |
model="gpt-4o-mini",
|
195 |
messages=[
|
196 |
+
{"role": "system", "content": f"""You are a Thai English teacher helping {level} students.
|
197 |
+
Provide feedback in Thai language that:
|
198 |
+
1. Points out ONE main grammar or vocabulary point
|
199 |
+
2. Explains the correct usage in simple Thai
|
200 |
+
3. Shows example sentences
|
201 |
+
4. Gives encouragement
|
202 |
+
|
203 |
+
Format example:
|
204 |
+
"🎯 คำว่า 'go' เมื่อพูดถึงเหตุการณ์ในอดีต ต้องเปลี่ยนเป็น 'went' นะคะ
|
|
|
|
|
|
|
|
|
205 |
|
206 |
+
ตัวอย่าง:
|
207 |
+
- ถูก: Yesterday, I went to school.
|
208 |
+
- ผิด: Yesterday, I go to school.
|
209 |
+
|
210 |
+
เก่งมากๆ เลยค่ะ ที่พยายามเขียนเป็นภาษาอังกฤษ! ✨"
|
211 |
"""},
|
212 |
+
{"role": "user", "content": f"Review this sentence and provide feedback in Thai: {text}"}
|
213 |
],
|
214 |
+
max_tokens=200,
|
215 |
temperature=0.7
|
216 |
)
|
217 |
return response.choices[0].message.content
|
218 |
except Exception as e:
|
219 |
st.error(f"Error generating feedback: {str(e)}")
|
220 |
+
return "🌟 พยายามได้ดีมากค่ะ/ครับ ลองเขียนต่อไปนะ!"
|
221 |
|
222 |
+
# Update the feedback display in the UI
|
223 |
if st.session_state.feedback:
|
224 |
+
st.markdown("""
|
225 |
+
<div class="thai-eng">
|
226 |
+
<div class="thai">📝 คำแนะนำจากคุณครู</div>
|
227 |
+
<div class="eng">Teacher's Feedback</div>
|
228 |
+
</div>
|
229 |
+
""", unsafe_allow_html=True)
|
230 |
+
|
231 |
feedback_container = st.container()
|
232 |
with feedback_container:
|
233 |
st.markdown(f"""
|
|
|
235 |
padding: 10px;
|
236 |
border-radius: 8px;
|
237 |
border-left: 4px solid #4CAF50;
|
238 |
+
margin: 5px 0;
|
239 |
+
font-family: "Sarabun", sans-serif;'>
|
240 |
{st.session_state.feedback}
|
241 |
</div>
|
242 |
""", unsafe_allow_html=True)
|
243 |
+
|
244 |
+
# Example feedback output will look like:
|
245 |
+
"""
|
246 |
+
🎯 คำว่า 'tree' เมื่อพูดถึงหลายต้น ต้องเติม s เป็น 'trees' นะคะ
|
247 |
+
|
248 |
+
ตัวอย่าง:
|
249 |
+
- ถูก: There are many trees in the forest.
|
250 |
+
- ผิด: There are many tree in the forest.
|
251 |
+
|
252 |
+
เขียนได้ดีมากเลยค่ะ ประโยคสื่อความหมายได้ชัดเจน! ✨
|
253 |
+
"""
|
254 |
|
255 |
+
# Example creative prompt will be simpler like:
|
256 |
+
"""
|
257 |
+
💭 ต่อไปตัวละครจะไปไหน?
|
258 |
+
Where will they go next?
|
259 |
+
"""
|
260 |
|
261 |
def update_achievements(text: str):
|
262 |
"""Update user achievements based on their writing."""
|