rairo commited on
Commit
6599845
·
verified ·
1 Parent(s): 0979743

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +33 -12
main.py CHANGED
@@ -165,24 +165,45 @@ def analyze_transcript_with_gemini(uid, project_id, transcript, duration_seconds
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
- prompt = f"""
169
- You are an expert performance coach. The user was practicing for a mock '{use_case}'.
170
- Their session was based on a document with these key points: "{context_text}"
171
-
172
- Your task is to analyze the following transcript. Your analysis must be a valid JSON object.
173
- Evaluate on: Communication Skills, Content Mastery, Engagement & Delivery, and Resilience Under Pressure.
174
-
175
- Provide: A score (0-100) for each, "qualitativeStrengths", "qualitativeImprovements", and "contextSpecificFeedback".
176
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  The JSON structure MUST be:
178
  {{
179
- "communicationScore": <integer>, "contentMasteryScore": <integer>, "engagementDeliveryScore": <integer>,
180
- "resilienceScore": <integer>, "qualitativeStrengths": "<string>", "qualitativeImprovements": "<string>",
 
 
 
 
181
  "contextSpecificFeedback": "<string>"
182
  }}
183
-
184
- Transcript: "{transcript}"
 
185
  """
 
 
186
  response = client.models.generate_content(model=MODEL_NAME, contents=prompt)
187
  feedback_json_text = response.text.strip().lstrip("```json").rstrip("```")
188
  feedback_data = json.loads(feedback_json_text)
 
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, MORE ROBUST PROMPT ---
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}'.
172
+ The user's session was based on a document with these key points: "{context_text}"
173
+
174
+ Your analysis must be structured as a valid JSON object. Do not include any text before or after the JSON object.
175
+
176
+ **Step 1: Substance Gatekeeper Analysis**
177
+ First, determine if the transcript contains a substantive conversation. A substantive conversation involves at least one meaningful question from the AI and one meaningful answer from the user. A transcript with only greetings (e.g., "Hello", "Hi there") or a single unanswered question is NOT substantive.
178
+ - If the conversation is NOT substantive, you MUST return a JSON object where all scores are 5, and the feedback fields explain that the session was too short to analyze.
179
+ - If the conversation IS substantive, proceed to Step 2.
180
+
181
+ **Step 2: Detailed Performance Evaluation**
182
+ Evaluate the user's performance on these four core criteria. Your evaluation must consider the DEPTH and COMPLETENESS of the user's responses.
183
+
184
+ 1. **Communication Skills:** Score based on clarity, confidence, and conciseness. A high score requires more than just a single clear sentence; it requires sustained clarity throughout a meaningful exchange.
185
+ 2. **Content Mastery:** Score based on subject knowledge and logical support for claims. A user who doesn't answer any core questions CANNOT receive a high score, no matter how well they greet the interviewer.
186
+ 3. **Engagement & Delivery:** Score based on tone, pacing, and audience awareness. This can only be judged in a real back-and-forth conversation, not from a simple greeting.
187
+ 4. **Resilience Under Pressure:** Score based on the ability to handle challenging follow-up questions. If no such questions were asked or answered, this score should be low by default.
188
+
189
+ **Penalty Clause:** Explicitly penalize short or incomplete sessions. If the user only answered one question and then the call ended, their scores should be significantly lower than if they had completed a full, multi-question session.
190
+
191
  The JSON structure MUST be:
192
  {{
193
+ "communicationScore": <integer>,
194
+ "contentMasteryScore": <integer>,
195
+ "engagementDeliveryScore": <integer>,
196
+ "resilienceScore": <integer>,
197
+ "qualitativeStrengths": "<string>",
198
+ "qualitativeImprovements": "<string>",
199
  "contextSpecificFeedback": "<string>"
200
  }}
201
+
202
+ Transcript to analyze:
203
+ "{transcript}"
204
  """
205
+ # --- END OF NEW PROMPT ---
206
+
207
  response = client.models.generate_content(model=MODEL_NAME, contents=prompt)
208
  feedback_json_text = response.text.strip().lstrip("```json").rstrip("```")
209
  feedback_data = json.loads(feedback_json_text)