Update app_utils.py
Browse files- app_utils.py +32 -0
app_utils.py
CHANGED
|
@@ -78,6 +78,38 @@ def parse_scores_from_feedback(feedback_text):
|
|
| 78 |
print("Score parsing failed:", e)
|
| 79 |
return {}
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
def generate_progress_summary(current_feedback, previous_feedback):
|
| 82 |
current_scores = parse_scores_from_feedback(current_feedback)
|
| 83 |
previous_scores = parse_scores_from_feedback(previous_feedback)
|
|
|
|
| 78 |
print("Score parsing failed:", e)
|
| 79 |
return {}
|
| 80 |
|
| 81 |
+
def generate_feedback(transcript, language, goal="general improvement", focus_areas=None, previous_transcript=None):
|
| 82 |
+
focus_str = ", ".join(focus_areas) if focus_areas else "Clarity, Structure, Fluency, Content Relevance, and Tone"
|
| 83 |
+
history_section = f"\n\nFor reference, their previous transcript was:\n{previous_transcript}" if previous_transcript else ""
|
| 84 |
+
|
| 85 |
+
prompt = f"""
|
| 86 |
+
You are a supportive communication coach helping a learner whose goal is: **{goal}**.
|
| 87 |
+
|
| 88 |
+
Evaluate the user's current speech based on the following areas:
|
| 89 |
+
{focus_str}
|
| 90 |
+
|
| 91 |
+
Give a score out of 10 and a short explanation for each area.
|
| 92 |
+
|
| 93 |
+
Then provide:
|
| 94 |
+
- A summary of strengths and improvement areas.
|
| 95 |
+
- One motivational line to end with.
|
| 96 |
+
|
| 97 |
+
Transcript:
|
| 98 |
+
{transcript}
|
| 99 |
+
{history_section}
|
| 100 |
+
""".strip()
|
| 101 |
+
|
| 102 |
+
response = client.chat.completions.create(
|
| 103 |
+
model="gpt-4",
|
| 104 |
+
messages=[
|
| 105 |
+
{"role": "system", "content": f"You are a warm and constructive communication coach responding in {language}."},
|
| 106 |
+
{"role": "user", "content": prompt}
|
| 107 |
+
],
|
| 108 |
+
temperature=0.7
|
| 109 |
+
)
|
| 110 |
+
return response.choices[0].message.content
|
| 111 |
+
|
| 112 |
+
|
| 113 |
def generate_progress_summary(current_feedback, previous_feedback):
|
| 114 |
current_scores = parse_scores_from_feedback(current_feedback)
|
| 115 |
previous_scores = parse_scores_from_feedback(previous_feedback)
|