Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -436,12 +436,11 @@ class ContentAnalyzer:
|
|
| 436 |
time.sleep(self.retry_delay * (2 ** attempt))
|
| 437 |
|
| 438 |
def _create_analysis_prompt(self, transcript: str) -> str:
|
| 439 |
-
"""Create the analysis prompt with smart timestamp handling"""
|
| 440 |
# First try to extract existing timestamps
|
| 441 |
timestamps = re.findall(r'\[(\d{2}:\d{2})\]', transcript)
|
| 442 |
|
| 443 |
if timestamps:
|
| 444 |
-
# Use existing timestamps
|
| 445 |
timestamp_instruction = f"""Use the EXACT timestamps from the transcript (e.g. {', '.join(timestamps[:3])}).
|
| 446 |
Do not create new timestamps."""
|
| 447 |
else:
|
|
@@ -453,17 +452,17 @@ Do not create new timestamps."""
|
|
| 453 |
3. Format as [MM:SS]
|
| 454 |
Example: If a quote starts at word 300, timestamp would be [02:00] (300 words / 150 words per minute)"""
|
| 455 |
|
| 456 |
-
# Add word position markers
|
| 457 |
words = transcript.split()
|
| 458 |
marked_transcript = ""
|
| 459 |
for i, word in enumerate(words):
|
| 460 |
-
if i % 150 == 0:
|
| 461 |
minutes = i // 150
|
| 462 |
marked_transcript += f"\n[{minutes:02d}:00] "
|
| 463 |
marked_transcript += word + " "
|
| 464 |
transcript = marked_transcript
|
| 465 |
|
| 466 |
-
prompt_template = """Analyze this teaching content
|
| 467 |
|
| 468 |
Transcript:
|
| 469 |
{transcript}
|
|
@@ -475,61 +474,107 @@ Required JSON structure:
|
|
| 475 |
{{
|
| 476 |
"Concept Assessment": {{
|
| 477 |
"Subject Matter Accuracy": {{
|
| 478 |
-
"Score": 1,
|
| 479 |
-
"Citations": ["[MM:SS] Quote
|
| 480 |
}},
|
| 481 |
"First Principles Approach": {{
|
| 482 |
-
"Score": 1,
|
| 483 |
-
"Citations": ["[MM:SS] Quote
|
| 484 |
}},
|
| 485 |
"Examples and Business Context": {{
|
| 486 |
-
"Score": 1,
|
| 487 |
-
"Citations": ["[MM:SS] Quote
|
| 488 |
}},
|
| 489 |
"Cohesive Storytelling": {{
|
| 490 |
-
"Score": 1,
|
| 491 |
-
"Citations": ["[MM:SS] Quote
|
| 492 |
}},
|
| 493 |
"Engagement and Interaction": {{
|
| 494 |
-
"Score": 1,
|
| 495 |
-
"Citations": ["[MM:SS] Quote
|
| 496 |
}},
|
| 497 |
"Professional Tone": {{
|
| 498 |
-
"Score": 1,
|
| 499 |
-
"Citations": ["[MM:SS] Quote
|
| 500 |
}}
|
| 501 |
}},
|
| 502 |
"Code Assessment": {{
|
| 503 |
"Depth of Explanation": {{
|
| 504 |
-
"Score": 1,
|
| 505 |
-
"Citations": ["[MM:SS] Quote
|
| 506 |
}},
|
| 507 |
"Output Interpretation": {{
|
| 508 |
-
"Score": 1,
|
| 509 |
-
"Citations": ["[MM:SS] Quote
|
| 510 |
}},
|
| 511 |
"Breaking down Complexity": {{
|
| 512 |
-
"Score": 1,
|
| 513 |
-
"Citations": ["[MM:SS] Quote
|
| 514 |
}}
|
| 515 |
}}
|
| 516 |
}}
|
| 517 |
|
| 518 |
-
Evaluation Criteria:
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
-
|
| 523 |
-
-
|
| 524 |
-
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 528 |
|
| 529 |
Important:
|
| 530 |
-
-
|
| 531 |
-
-
|
| 532 |
-
-
|
|
|
|
|
|
|
| 533 |
|
| 534 |
return prompt_template.format(
|
| 535 |
transcript=transcript,
|
|
@@ -2618,4 +2663,5 @@ def main():
|
|
| 2618 |
st.error(f"Application error: {str(e)}")
|
| 2619 |
|
| 2620 |
if __name__ == "__main__":
|
| 2621 |
-
main()
|
|
|
|
|
|
| 436 |
time.sleep(self.retry_delay * (2 ** attempt))
|
| 437 |
|
| 438 |
def _create_analysis_prompt(self, transcript: str) -> str:
|
| 439 |
+
"""Create the analysis prompt with smart timestamp handling and stricter evaluation criteria"""
|
| 440 |
# First try to extract existing timestamps
|
| 441 |
timestamps = re.findall(r'\[(\d{2}:\d{2})\]', transcript)
|
| 442 |
|
| 443 |
if timestamps:
|
|
|
|
| 444 |
timestamp_instruction = f"""Use the EXACT timestamps from the transcript (e.g. {', '.join(timestamps[:3])}).
|
| 445 |
Do not create new timestamps."""
|
| 446 |
else:
|
|
|
|
| 452 |
3. Format as [MM:SS]
|
| 453 |
Example: If a quote starts at word 300, timestamp would be [02:00] (300 words / 150 words per minute)"""
|
| 454 |
|
| 455 |
+
# Add word position markers
|
| 456 |
words = transcript.split()
|
| 457 |
marked_transcript = ""
|
| 458 |
for i, word in enumerate(words):
|
| 459 |
+
if i % 150 == 0:
|
| 460 |
minutes = i // 150
|
| 461 |
marked_transcript += f"\n[{minutes:02d}:00] "
|
| 462 |
marked_transcript += word + " "
|
| 463 |
transcript = marked_transcript
|
| 464 |
|
| 465 |
+
prompt_template = """Analyze this teaching content with strict evaluation criteria. Score 1 only if ALL requirements are fully met.
|
| 466 |
|
| 467 |
Transcript:
|
| 468 |
{transcript}
|
|
|
|
| 474 |
{{
|
| 475 |
"Concept Assessment": {{
|
| 476 |
"Subject Matter Accuracy": {{
|
| 477 |
+
"Score": 1, # Score 1 ONLY if NO factual errors or misconceptions are present
|
| 478 |
+
"Citations": ["[MM:SS] Quote demonstrating accuracy or error"]
|
| 479 |
}},
|
| 480 |
"First Principles Approach": {{
|
| 481 |
+
"Score": 1, # Score 1 ONLY if fundamentals are clearly explained BEFORE introducing complex concepts
|
| 482 |
+
"Citations": ["[MM:SS] Quote showing fundamental concept explanation"]
|
| 483 |
}},
|
| 484 |
"Examples and Business Context": {{
|
| 485 |
+
"Score": 1, # Score 1 ONLY if MULTIPLE relevant real-world examples are provided
|
| 486 |
+
"Citations": ["[MM:SS] Quote containing practical example"]
|
| 487 |
}},
|
| 488 |
"Cohesive Storytelling": {{
|
| 489 |
+
"Score": 1, # Score 1 ONLY if concepts flow logically with clear transitions
|
| 490 |
+
"Citations": ["[MM:SS] Quote showing topic transition or connection"]
|
| 491 |
}},
|
| 492 |
"Engagement and Interaction": {{
|
| 493 |
+
"Score": 1, # Score 1 ONLY if MULTIPLE engagement techniques are used effectively
|
| 494 |
+
"Citations": ["[MM:SS] Quote showing audience engagement"]
|
| 495 |
}},
|
| 496 |
"Professional Tone": {{
|
| 497 |
+
"Score": 1, # Score 1 ONLY if consistently professional language is maintained
|
| 498 |
+
"Citations": ["[MM:SS] Quote demonstrating tone"]
|
| 499 |
}}
|
| 500 |
}},
|
| 501 |
"Code Assessment": {{
|
| 502 |
"Depth of Explanation": {{
|
| 503 |
+
"Score": 1, # Score 1 ONLY if code concepts are explained thoroughly with implementation details
|
| 504 |
+
"Citations": ["[MM:SS] Quote showing detailed code explanation"]
|
| 505 |
}},
|
| 506 |
"Output Interpretation": {{
|
| 507 |
+
"Score": 1, # Score 1 ONLY if code outputs are explained with their significance
|
| 508 |
+
"Citations": ["[MM:SS] Quote demonstrating output explanation"]
|
| 509 |
}},
|
| 510 |
"Breaking down Complexity": {{
|
| 511 |
+
"Score": 1, # Score 1 ONLY if complex concepts are broken into manageable parts
|
| 512 |
+
"Citations": ["[MM:SS] Quote showing concept breakdown"]
|
| 513 |
}}
|
| 514 |
}}
|
| 515 |
}}
|
| 516 |
|
| 517 |
+
Strict Evaluation Criteria:
|
| 518 |
+
|
| 519 |
+
Concept Assessment:
|
| 520 |
+
1. Subject Matter Accuracy
|
| 521 |
+
- MUST have zero factual errors or misconceptions
|
| 522 |
+
- All technical terms used correctly
|
| 523 |
+
- No oversimplification that leads to incorrect understanding
|
| 524 |
+
|
| 525 |
+
2. First Principles Approach
|
| 526 |
+
- MUST explain fundamental concepts before advanced topics
|
| 527 |
+
- Clear progression from basic to complex ideas
|
| 528 |
+
- Core concepts defined before being used in explanations
|
| 529 |
+
|
| 530 |
+
3. Examples and Business Context
|
| 531 |
+
- MUST include at least 2 relevant real-world examples
|
| 532 |
+
- Examples should directly relate to the concept
|
| 533 |
+
- Business context should be clearly explained
|
| 534 |
+
|
| 535 |
+
4. Cohesive Storytelling
|
| 536 |
+
- MUST have clear logical flow between topics
|
| 537 |
+
- Explicit connections between related concepts
|
| 538 |
+
- Smooth transitions between subjects
|
| 539 |
+
- No abrupt topic changes
|
| 540 |
+
|
| 541 |
+
5. Engagement and Interaction
|
| 542 |
+
- MUST use at least 2 different engagement techniques
|
| 543 |
+
- Rhetorical questions or direct audience involvement
|
| 544 |
+
- Clear checks for understanding
|
| 545 |
+
- Interactive elements in presentation
|
| 546 |
+
|
| 547 |
+
6. Professional Tone
|
| 548 |
+
- MUST maintain consistent professional language
|
| 549 |
+
- No casual or inappropriate expressions
|
| 550 |
+
- Clear and confident delivery
|
| 551 |
+
- Appropriate technical vocabulary
|
| 552 |
+
|
| 553 |
+
Code Assessment:
|
| 554 |
+
1. Depth of Explanation
|
| 555 |
+
- MUST explain both what code does AND why
|
| 556 |
+
- Implementation details clearly covered
|
| 557 |
+
- Key programming concepts explained
|
| 558 |
+
- Important design decisions justified
|
| 559 |
+
|
| 560 |
+
2. Output Interpretation
|
| 561 |
+
- MUST explain significance of all outputs
|
| 562 |
+
- Clear connection between code and results
|
| 563 |
+
- Error cases covered
|
| 564 |
+
- Expected vs actual results discussed
|
| 565 |
+
|
| 566 |
+
3. Breaking down Complexity
|
| 567 |
+
- MUST divide complex topics into clear sub-components
|
| 568 |
+
- Step-by-step explanation of difficult concepts
|
| 569 |
+
- Clear progression in complexity
|
| 570 |
+
- Logical organization of technical content
|
| 571 |
|
| 572 |
Important:
|
| 573 |
+
- Score 1 ONLY if ALL criteria for that category are met
|
| 574 |
+
- Each citation must include exact timestamp and relevant quote
|
| 575 |
+
- Citations should clearly demonstrate how criteria are/aren't met
|
| 576 |
+
- Be strict and objective in scoring
|
| 577 |
+
- Default to 0 if any doubt about meeting ALL criteria"""
|
| 578 |
|
| 579 |
return prompt_template.format(
|
| 580 |
transcript=transcript,
|
|
|
|
| 2663 |
st.error(f"Application error: {str(e)}")
|
| 2664 |
|
| 2665 |
if __name__ == "__main__":
|
| 2666 |
+
main()
|
| 2667 |
+
|