Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -404,55 +404,6 @@ class ContentAnalyzer:
|
|
| 404 |
logger.error(f"Missing Score or Citations in {category}.{subcategory}")
|
| 405 |
raise ValueError(f"Missing Score or Citations in {category}.{subcategory}")
|
| 406 |
|
| 407 |
-
# Add validation for citations
|
| 408 |
-
def validate_citations(citations: List[str]) -> bool:
|
| 409 |
-
if not citations:
|
| 410 |
-
return False
|
| 411 |
-
|
| 412 |
-
for citation in citations:
|
| 413 |
-
# Check for timestamp format [MM:SS]
|
| 414 |
-
if not re.search(r'\[\d{2}:\d{2}\]', citation):
|
| 415 |
-
return False
|
| 416 |
-
# Check for meaningful content (at least 10 words)
|
| 417 |
-
content = re.sub(r'\[\d{2}:\d{2}\]', '', citation).strip()
|
| 418 |
-
if len(content.split()) < 10:
|
| 419 |
-
return False
|
| 420 |
-
return True
|
| 421 |
-
|
| 422 |
-
# Add validation for each category score
|
| 423 |
-
result = json.loads(result_text)
|
| 424 |
-
for category in ["Concept Assessment", "Code Assessment"]:
|
| 425 |
-
if category in result:
|
| 426 |
-
for subcategory, details in result[category].items():
|
| 427 |
-
# Validate citations first
|
| 428 |
-
if not validate_citations(details.get("Citations", [])):
|
| 429 |
-
details["Score"] = 0 # Force score to 0 if citations are invalid
|
| 430 |
-
details["Citations"].append("[00:00] Invalid or insufficient citation format. Requires specific examples with timestamps.")
|
| 431 |
-
|
| 432 |
-
# Additional validation based on subcategory
|
| 433 |
-
if subcategory == "Examples and Business Context":
|
| 434 |
-
# Count actual examples in citations
|
| 435 |
-
example_count = sum(1 for citation in details.get("Citations", [])
|
| 436 |
-
if "example" in citation.lower() or "case" in citation.lower())
|
| 437 |
-
if example_count < 2:
|
| 438 |
-
details["Score"] = 0
|
| 439 |
-
details["Citations"].append("[00:00] Insufficient number of concrete examples. At least 2 required.")
|
| 440 |
-
|
| 441 |
-
elif subcategory == "Engagement and Interaction":
|
| 442 |
-
# Count engagement points
|
| 443 |
-
engagement_count = sum(1 for citation in details.get("Citations", [])
|
| 444 |
-
if any(word in citation.lower() for word in ["question", "ask", "interact", "engage"]))
|
| 445 |
-
if engagement_count < 3:
|
| 446 |
-
details["Score"] = 0
|
| 447 |
-
details["Citations"].append("[00:00] Insufficient engagement points. At least 3 required.")
|
| 448 |
-
|
| 449 |
-
# Validate professional tone
|
| 450 |
-
elif subcategory == "Professional Tone":
|
| 451 |
-
unprofessional_indicators = ["um", "uh", "like", "you know", "stuff", "things"]
|
| 452 |
-
if any(indicator in ' '.join(details.get("Citations", [])).lower() for indicator in unprofessional_indicators):
|
| 453 |
-
details["Score"] = 0
|
| 454 |
-
details["Citations"].append("[00:00] Unprofessional language detected. Maintain formal teaching tone.")
|
| 455 |
-
|
| 456 |
return result
|
| 457 |
|
| 458 |
except json.JSONDecodeError as json_error:
|
|
|
|
| 404 |
logger.error(f"Missing Score or Citations in {category}.{subcategory}")
|
| 405 |
raise ValueError(f"Missing Score or Citations in {category}.{subcategory}")
|
| 406 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
return result
|
| 408 |
|
| 409 |
except json.JSONDecodeError as json_error:
|