Update main.py
Browse files
main.py
CHANGED
|
@@ -160,36 +160,48 @@ def _get_context_specific_instructions(use_case):
|
|
| 160 |
def analyze_transcript_with_gemini(uid, project_id, transcript, duration_seconds):
|
| 161 |
logger.info(f"Starting transcript analysis for project {project_id}.")
|
| 162 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
project_ref = db_ref.child(f'projects/{uid}/{project_id}')
|
| 164 |
project_data = project_ref.get()
|
| 165 |
if not project_data: raise ValueError("Project not found for analysis.")
|
| 166 |
use_case = project_data.get('detectedUseCase', 'General')
|
| 167 |
context_text = project_data.get('key_points', project_data.get('originalBriefingText', ''))
|
| 168 |
|
| 169 |
-
# --- NEW,
|
| 170 |
prompt = f"""
|
| 171 |
-
You are an expert performance coach and communication analyst. Your task is to analyze the following transcript of a mock '{use_case}' with fairness and
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
-
Your analysis must be structured as a valid JSON object.
|
| 175 |
|
| 176 |
-
**Step 1: Assess Conversation
|
| 177 |
-
First, evaluate
|
| 178 |
|
| 179 |
-
**Step 2: Detailed Performance Evaluation with Scoring Rubric**
|
| 180 |
-
Evaluate the user's performance on the four core criteria.
|
| 181 |
|
| 182 |
-
* **
|
| 183 |
-
* **
|
| 184 |
-
* **
|
|
|
|
| 185 |
|
| 186 |
-
**Core Criteria
|
| 187 |
-
1. **Communication Skills:**
|
| 188 |
-
2. **Content Mastery:**
|
| 189 |
-
3. **Engagement & Delivery:**
|
| 190 |
-
4. **Resilience Under Pressure:**
|
| 191 |
|
| 192 |
-
**Final Instruction:** Your
|
| 193 |
|
| 194 |
The JSON structure MUST be:
|
| 195 |
{{
|
|
|
|
| 160 |
def analyze_transcript_with_gemini(uid, project_id, transcript, duration_seconds):
|
| 161 |
logger.info(f"Starting transcript analysis for project {project_id}.")
|
| 162 |
try:
|
| 163 |
+
# --- NEW: Fetch user's name for explicit identification ---
|
| 164 |
+
user_ref = db_ref.child(f'users/{uid}')
|
| 165 |
+
user_data = user_ref.get()
|
| 166 |
+
user_name = user_data.get('displayName', 'the user') if user_data else 'the user'
|
| 167 |
+
# --- END NEW ---
|
| 168 |
+
|
| 169 |
project_ref = db_ref.child(f'projects/{uid}/{project_id}')
|
| 170 |
project_data = project_ref.get()
|
| 171 |
if not project_data: raise ValueError("Project not found for analysis.")
|
| 172 |
use_case = project_data.get('detectedUseCase', 'General')
|
| 173 |
context_text = project_data.get('key_points', project_data.get('originalBriefingText', ''))
|
| 174 |
|
| 175 |
+
# --- NEW, SURGICALLY PRECISE PROMPT ---
|
| 176 |
prompt = f"""
|
| 177 |
+
You are an expert performance coach and communication analyst. Your task is to analyze the following transcript of a mock '{use_case}' with fairness and precision.
|
| 178 |
+
|
| 179 |
+
**CRITICAL CONTEXT:**
|
| 180 |
+
- You are analyzing a session for a user named **'{user_name}'**.
|
| 181 |
+
- In the transcript, the speaker labeled 'User' is **'{user_name}'**.
|
| 182 |
+
- Any other names mentioned by the user (e.g., Eric, Daniel, Rachel) are part of the role-play scenario and should NOT be confused with the user you are evaluating.
|
| 183 |
+
- The user's session was based on a document with these key points: "{context_text}"
|
| 184 |
|
| 185 |
+
Your analysis must be structured as a valid JSON object.
|
| 186 |
|
| 187 |
+
**Step 1: Assess Conversation Substance**
|
| 188 |
+
First, evaluate if the transcript contains a "substantive answer." A substantive answer is defined as a user's response to a direct question from the AI. An introductory statement or greeting from the user does NOT count as a substantive answer.
|
| 189 |
|
| 190 |
+
**Step 2: Detailed Performance Evaluation with a Strict Scoring Rubric**
|
| 191 |
+
Evaluate the user's performance on the four core criteria. You MUST follow this rubric:
|
| 192 |
|
| 193 |
+
* **Crucial Scoring Rule:** To award a score above 40 in **any** category, the user must have provided at least one complete, on-topic, "substantive answer" as defined in Step 1.
|
| 194 |
+
* **0-40 (Needs Significant Work):** Use this range if the session does not contain a substantive answer. Even if the user's introduction is excellent, if they do not answer a question, their scores must remain in this range.
|
| 195 |
+
* **41-70 (Developing):** Use this for users who provide at least one substantive answer but struggle with clarity, depth, or confidence.
|
| 196 |
+
* **71-100 (Proficient to Excellent):** Use this for users who provide clear, confident, and well-supported answers.
|
| 197 |
|
| 198 |
+
**Core Criteria:**
|
| 199 |
+
1. **Communication Skills:** Clarity and confidence.
|
| 200 |
+
2. **Content Mastery:** Relevance and support for claims. Cannot be high without a substantive answer.
|
| 201 |
+
3. **Engagement & Delivery:** Tone and pacing.
|
| 202 |
+
4. **Resilience Under Pressure:** Handling follow-up questions. Cannot be scored high if no questions were answered.
|
| 203 |
|
| 204 |
+
**Final Instruction:** Your qualitative feedback should reflect the score. If scores are low because the session was too short, you can praise the introduction in the "Strengths" section (e.g., "Provides a clear, confident opening statement.") but you MUST state in the "Areas for Improvement" section that a full analysis is impossible without answering questions.
|
| 205 |
|
| 206 |
The JSON structure MUST be:
|
| 207 |
{{
|