Update app.py
Browse files
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
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
-
|
| 30 |
-
-
|
| 31 |
-
- Grammar
|
| 32 |
-
- Filler words
|
| 33 |
-
- Tone and pacing
|
| 34 |
-
- Sentence structure
|
| 35 |
-
- Overall communication effectiveness
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
|
|
|
| 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 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 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
|