ankban commited on
Commit
455dff0
·
verified ·
1 Parent(s): ff36adf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -20
app.py CHANGED
@@ -20,24 +20,28 @@ model = WhisperModel("base", compute_type="int8") # Fastest CPU option
20
  openai.api_key = os.getenv("OPENAI_API_KEY")
21
 
22
  # Prompt template
23
- PROMPT_TEMPLATE = """
24
- You're a communication coach helping users improve their spoken English.
25
 
26
- Evaluate the following speech transcript and provide helpful, constructive feedback.
 
 
 
 
 
27
 
28
- Focus on:
29
- - Clarity
30
- - Fluency
31
- - Grammar
32
- - Filler words
33
- - Tone and pacing
34
- - Sentence structure
35
- - Overall communication effectiveness
36
 
37
- Transcript:
38
- \"\"\"{transcript}\"\"\"
 
 
 
39
 
40
- Provide concise feedback in 3-4 bullet points followed by a one-line motivational sentence.
 
41
  """
42
 
43
  # Convert uploaded audio to 16kHz mono WAV
@@ -54,12 +58,12 @@ def generate_feedback_with_llm(transcript):
54
  prompt = PROMPT_TEMPLATE.format(transcript=transcript.strip())
55
 
56
  response = client.chat.completions.create(
57
- model="gpt-4-1106-preview",
58
- temperature=0.7,
59
- messages=[
60
- {"role": "system", "content": "You are a helpful communication tutor."},
61
- {"role": "user", "content": prompt}
62
- ]
63
  )
64
 
65
  return response.choices[0].message.content
 
20
  openai.api_key = os.getenv("OPENAI_API_KEY")
21
 
22
  # Prompt template
23
+ PROMPT_TEMPLATE = f"""
24
+ You are a communication coach evaluating a user's spoken response.
25
 
26
+ Please evaluate their speech using the following **five dimensions**:
27
+ 1. Clarity
28
+ 2. Structure
29
+ 3. Fluency
30
+ 4. Content Relevance
31
+ 5. Tone & Expression
32
 
33
+ For each category:
34
+ - Give a score from 0 to 10
35
+ - Provide a brief but detailed explanation
 
 
 
 
 
36
 
37
+ Then:
38
+ - Summarize their overall performance in 3–4 lines
39
+ - End with one motivational sentence
40
+
41
+ Make sure your tone is constructive and supportive, even if the scores are low.
42
 
43
+ Transcript:
44
+ {transcript}
45
  """
46
 
47
  # Convert uploaded audio to 16kHz mono WAV
 
58
  prompt = PROMPT_TEMPLATE.format(transcript=transcript.strip())
59
 
60
  response = client.chat.completions.create(
61
+ model="gpt-4",
62
+ messages=[
63
+ {"role": "system", "content": "You are a communication coach that gives structured and emotionally aware feedback."},
64
+ {"role": "user", "content": prompt}
65
+ ],
66
+ temperature=0.7
67
  )
68
 
69
  return response.choices[0].message.content