ankban commited on
Commit
d981ac8
·
verified ·
1 Parent(s): 2be951d

Update app_utils.py

Browse files
Files changed (1) hide show
  1. app_utils.py +25 -19
app_utils.py CHANGED
@@ -63,37 +63,43 @@ def transcribe_audio(audio_path):
63
  segments, _ = model.transcribe(audio_path)
64
  return " ".join([segment.text for segment in segments])
65
 
66
- # === GPT ===
67
- def generate_feedback(transcript, language):
68
- prompt = f"""You are a communication coach. Please respond in [language={language}].
69
- Evaluate the user's speech on:
70
- 1. Clarity
71
- 2. Structure
72
- 3. Fluency
73
- 4. Content Relevance
74
- 5. Tone & Expression
75
- Each category:
76
- - Score out of 10
77
- - Short explanation
78
- End with:
79
- - Overall feedback summary
80
- - One motivational line
 
 
81
  Transcript:
82
  {transcript}
83
- """
 
 
84
  response = client.chat.completions.create(
85
  model="gpt-4",
86
  messages=[
87
- {"role": "system", "content": f"You are a supportive communication coach responding in {language}."},
88
  {"role": "user", "content": prompt}
89
  ],
90
  temperature=0.7
91
  )
92
  return response.choices[0].message.content
93
 
 
94
  def generate_example_response(transcript, language):
95
- prompt = f"""You are a communication coach. Rewrite this speech to make it more polished, fluent, and confident.
96
  Keep the meaning and tone the same, but improve clarity and structure.
 
97
  Transcript:
98
  {transcript}
99
  """
@@ -104,4 +110,4 @@ Transcript:
104
  {"role": "user", "content": prompt}
105
  ]
106
  )
107
- return response.choices[0].message.content
 
63
  segments, _ = model.transcribe(audio_path)
64
  return " ".join([segment.text for segment in segments])
65
 
66
+ # === GPT: Personalized Feedback ===
67
+ def generate_feedback(transcript, language, goal="general improvement", focus_areas=None, previous_transcript=None):
68
+ focus_str = ", ".join(focus_areas) if focus_areas else "Clarity, Structure, Fluency, Content Relevance, and Tone"
69
+ history_section = f"\n\nFor reference, their previous transcript was:\n{previous_transcript}" if previous_transcript else ""
70
+
71
+ prompt = f"""
72
+ You are a supportive communication coach helping a learner whose goal is: **{goal}**.
73
+
74
+ Evaluate the user's current speech based on the following areas:
75
+ {focus_str}
76
+
77
+ Give a score out of 10 and a short explanation for each area.
78
+
79
+ Then provide:
80
+ - A summary of strengths and improvement areas.
81
+ - One motivational line to end with.
82
+
83
  Transcript:
84
  {transcript}
85
+ {history_section}
86
+ """.strip()
87
+
88
  response = client.chat.completions.create(
89
  model="gpt-4",
90
  messages=[
91
+ {"role": "system", "content": f"You are a warm and constructive communication coach responding in {language}."},
92
  {"role": "user", "content": prompt}
93
  ],
94
  temperature=0.7
95
  )
96
  return response.choices[0].message.content
97
 
98
+ # === GPT: Improved Response ===
99
  def generate_example_response(transcript, language):
100
+ prompt = f"""Rewrite this speech to make it more polished, fluent, and confident.
101
  Keep the meaning and tone the same, but improve clarity and structure.
102
+
103
  Transcript:
104
  {transcript}
105
  """
 
110
  {"role": "user", "content": prompt}
111
  ]
112
  )
113
+ return response.choices[0].message.content